@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
private void seekToNextMarker() throws IOException { while (in.getFilePointer() < in.length()) { String check = in.readString(3); if (check.equals(MARKER)) { in.skipBytes(1); return; } in.seek(in.getFilePointer() - 2); } }
@Override public byte[] decompress(RandomAccessInputStream in, CodecOptions options) throws CodecException, IOException { if (in == null) throw new IllegalArgumentException("No data to decompress."); byte[] b = new byte[(int) (in.length() - in.getFilePointer())]; in.read(b); return decompress(b, options); }
@Override public int available() throws IOException { long remain = length() - getFilePointer(); if (remain > Integer.MAX_VALUE) remain = Integer.MAX_VALUE; return (int) remain; }
/** Reads the contents of the given file into a string. */ public static String readFile(String id) throws IOException { RandomAccessInputStream in = new RandomAccessInputStream(id); long idLen = in.length(); if (idLen > Integer.MAX_VALUE) { throw new IOException("File too large"); } int len = (int) idLen; String data = in.readString(len); in.close(); return data; }
@Override protected void initFile(String id) throws FormatException, IOException { RandomAccessInputStream s = new RandomAccessInputStream(id); use64Bit = s.length() >= Math.pow(2, 32); s.close(); super.initFile(id); }
public AttachmentEntry(RandomAccessInputStream s) throws IOException { schemaType = s.readString(2); s.skipBytes(10); // reserved filePosition = s.readLong(); filePart = s.readInt(); contentGUID = s.readString(16); contentFileType = s.readString(8); name = s.readString(80); }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 4; if (!FormatTools.validStream(stream, blockLen, false)) return false; stream.order(true); int checkLittleEndian = stream.readInt(); stream.seek(stream.getFilePointer() - 4); stream.order(false); int checkBigEndian = stream.readInt(); return checkLittleEndian == MAGIC || checkBigEndian == MAGIC; }
private int getFileVersion(RandomAccessInputStream stream) throws IOException { stream.seek(0); stream.order(LITTLE_ENDIAN); try { final String magicString = stream.readString(FILE_MAGIC_STRING.length()); final short magicNumber = stream.readShort(); final int version = stream.readInt(); if (magicString.equals(FILE_MAGIC_STRING) && magicNumber == MAGIC_NUMBER) { return version; } } catch(IOException exception) { } return - 1; }
/** Searches for the divider tag in blocks of the given size. */ public long testBlock(String filename, int blockSize) throws IOException { LOGGER.info("Searching for divider in blocks of {}...", blockSize); long start = System.currentTimeMillis(); RandomAccessInputStream in = new RandomAccessInputStream(filename); long offset = in.findString(blockSize, TAG).length(); in.close(); long end = System.currentTimeMillis(); LOGGER.info("Search result: {} -- in {} ms", offset, end - start); return offset; }
private void copyPixels(int x, int y, int w, int h, int bpp, int scanlinePad, byte[] pix, byte[] buf, boolean split) throws IOException { if (split) { pix = ImageTools.splitChannels(pix, lastChannel, getEffectiveSizeC(), bpp, false, true); } RandomAccessInputStream s = new RandomAccessInputStream(pix); readPlane(s, x, y, w, h, scanlinePad, buf); s.close(); }
@Override public void loadStop() throws IOException { if (loadStream != null) { loadStream.close(); loadStream = null; } }
public RandomAccessInputStream getStream() throws IOException { if (stream != null) { return stream; } return new RandomAccessInputStream(filename, BUFFER_SIZE); } }
public long[] toArray() throws IOException { long fp = stream.getFilePointer(); stream.seek(start); byte[] rawBytes = new byte[size * 8]; stream.readFully(rawBytes); stream.seek(fp); return (long[]) DataTools.makeDataArray(rawBytes, 8, false, stream.isLittleEndian()); }
@Override public int read() throws IOException { int b = readByte(); if (b == -1 && (getFilePointer() >= length())) return 0; return b; }
/** Cut off header bytes from a resource fork file. */ private void stripHeader() throws IOException { in.seek(0); while (!in.readString(4).equals("moov")) { in.seek(in.getFilePointer() - 2); } in.seek(in.getFilePointer() - 8); }