/** 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 RandomAccessInputStream getDecompressedStream(String filename) throws FormatException, IOException { RandomAccessInputStream s = new RandomAccessInputStream(filename); if (checkSuffix(filename, "c01")) { LOGGER.info("Decompressing file"); try { s.seek(4); ZlibCodec codec = new ZlibCodec(); byte[] file = codec.decompress(s, null); return new RandomAccessInputStream(file); } finally { s.close(); } } return s; }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
private RandomAccessInputStream getDecompressedStream(String filename) throws FormatException, IOException { RandomAccessInputStream s = new RandomAccessInputStream(filename); if (checkSuffix(filename, "c01")) { LOGGER.info("Decompressing file"); try { s.seek(4); ZlibCodec codec = new ZlibCodec(); byte[] file = codec.decompress(s, null); return new RandomAccessInputStream(file); } finally { s.close(); } } return s; }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(currentId); in.seek(0); service = new JPEGTurboServiceImpl(); try { service.initialize(in, getSizeX(), getSizeY()); } catch (ServiceException se) { service = null; throw new IOException("Could not initialize JPEG service", se); } }
public void fillInData() throws IOException { RandomAccessInputStream s = getStream(); try { s.order(isLittleEndian()); s.seek(startingPosition + 16); // read the segment header allocatedSize = s.readLong(); usedSize = s.readLong(); if (usedSize == 0) { usedSize = allocatedSize; } } finally { if (stream == null) { s.close(); } } }
@Override public boolean isThisType(byte[] block) { try { RandomAccessInputStream stream = new RandomAccessInputStream(block); boolean isThisType = isThisType(stream); stream.close(); return isThisType; } catch (IOException e) { LOGGER.debug("", e); } return false; }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(currentId); in.seek(0); service = new JPEGTurboServiceImpl(); try { service.initialize(in, getSizeX(), getSizeY()); } catch (ServiceException se) { service = null; throw new IOException("Could not initialize JPEG service", se); } }
public void fillInData() throws IOException { RandomAccessInputStream s = getStream(); try { s.order(isLittleEndian()); s.seek(startingPosition + 16); // read the segment header allocatedSize = s.readLong(); usedSize = s.readLong(); if (usedSize == 0) { usedSize = allocatedSize; } } finally { if (stream == null) { s.close(); } } }
@Override public boolean isThisType(byte[] block) { try { RandomAccessInputStream stream = new RandomAccessInputStream(block); boolean isThisType = isThisType(stream); stream.close(); return isThisType; } catch (IOException e) { LOGGER.debug("", e); } return false; }
/** * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ @Override public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); if (files.size() > 1) { in = new RandomAccessInputStream(files.get(no)); in.order(isLittleEndian()); } in.seek(pixelOffsets[no]); readPlane(in, x, getSizeY() - y - h, w, h, buf); int bpp = FormatTools.getBytesPerPixel(getPixelType()); byte[] rowBuf = new byte[w * bpp]; for (int row=0; row<h/2; row++) { int src = row * rowBuf.length; int dest = (h - row - 1) * rowBuf.length; System.arraycopy(buf, src, rowBuf, 0, rowBuf.length); System.arraycopy(buf, dest, buf, src, rowBuf.length); System.arraycopy(rowBuf, 0, buf, dest, rowBuf.length); } if (files.size() > 1) { in.close(); } return buf; }
@Override public void fillInData() throws IOException { super.fillInData(); RandomAccessInputStream s = getStream(); try { s.order(isLittleEndian()); s.seek(startingPosition + HEADER_SIZE); int entryCount = s.readInt(); s.skipBytes(124); entries = new DirectoryEntry[entryCount]; for (int i=0; i<entryCount; i++) { entries[i] = new DirectoryEntry(s); } } finally { if (stream == null) { s.close(); } } } }
@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); }
/** * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ @Override public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); if (files.size() > 1) { in = new RandomAccessInputStream(files.get(no)); in.order(isLittleEndian()); } in.seek(pixelOffsets[no]); readPlane(in, x, getSizeY() - y - h, w, h, buf); int bpp = FormatTools.getBytesPerPixel(getPixelType()); byte[] rowBuf = new byte[w * bpp]; for (int row=0; row<h/2; row++) { int src = row * rowBuf.length; int dest = (h - row - 1) * rowBuf.length; System.arraycopy(buf, src, rowBuf, 0, rowBuf.length); System.arraycopy(buf, dest, buf, src, rowBuf.length); System.arraycopy(rowBuf, 0, buf, dest, rowBuf.length); } if (files.size() > 1) { in.close(); } return buf; }
@Override public void fillInData() throws IOException { super.fillInData(); RandomAccessInputStream s = getStream(); try { s.order(isLittleEndian()); s.seek(startingPosition + HEADER_SIZE); int entryCount = s.readInt(); s.skipBytes(124); entries = new DirectoryEntry[entryCount]; for (int i=0; i<entryCount; i++) { entries[i] = new DirectoryEntry(s); } } finally { if (stream == null) { s.close(); } } } }
/** 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; }
private int getExtraSeries(String file) throws FormatException, IOException { if (in != null) in.close(); in = new RandomAccessInputStream(file, 16); boolean littleEndian = in.read() == TiffConstants.LITTLE; in.order(littleEndian); tiffParser = new TiffParser(in); IFD ifd = tiffParser.getFirstIFD(); RandomAccessInputStream ras = getCZTag(ifd); if (ras == null) return 1; ras.order(littleEndian); ras.seek(264); dimensionP = ras.readInt(); dimensionM = ras.readInt(); ras.close(); int nSeries = dimensionM * dimensionP; return nSeries <= 0 ? 1 : nSeries; }