/** 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); }
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); } }
private int findNextOffset(RandomAccessInputStream s, byte[] marker) throws IOException { for (long i=s.getFilePointer(); i<s.length()-marker.length; i++) { s.seek(i); boolean found = true; for (int q=0; q<marker.length; q++) { if (marker[q] != s.readByte()) { found = false; break; } } if (found) return (int) (i + marker.length); } return -1; }
/** * @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 (getSeries() != lastSeries) { if (seriesStream != null) { seriesStream.close(); } seriesStream = new RandomAccessInputStream(pixelsFiles.get(getSeries())); lastSeries = getSeries(); } long offset = (long) no * FormatTools.getPlaneSize(this); if (offset < seriesStream.length()) { seriesStream.seek(offset); readPlane(seriesStream, x, y, w, h, buf); } return buf; }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = true; in.order(isLittleEndian()); in.seek(44); m.sizeX = in.readInt(); m.sizeY = in.readInt(); m.pixelType = FormatTools.UINT32; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYZCT"; padding = (int) ((in.length() - FormatTools.getPlaneSize(this)) / (getSizeY() * 4)); addGlobalMeta("Padding bytes", padding); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
/** * Read the footer data for the current database file. * @throws IOException if the footer cannot be read from the file * @throws MetakitException if the footer is not valid for the Metakit format */ private void readFooter() throws IOException, MetakitException { stream.skipBytes(4); long headerLocation = stream.readInt(); stream.skipBytes(4); long tocLocation = stream.readInt(); stream.seek(tocLocation); readTOC(); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); in.seek(348); m.sizeX = in.readInt(); m.sizeY = in.readInt(); in.skipBytes(4); int bpp = in.readInt(); addGlobalMeta("Bytes per pixel", bpp); m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, bpp == 4); m.littleEndian = false; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.rgb = false; m.interleaved = false; m.dimensionOrder = "XYZCT"; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
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; }
public long get(int index) throws IOException { long fp = stream.getFilePointer(); stream.seek(start + index * 8); long value = stream.readLong(); stream.seek(fp); return value; }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); in.seek(524); m.sizeY = in.readShort(); in.skipBytes(6); m.sizeX = in.readShort(); m.pixelType = FormatTools.UINT8; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYZCT"; m.littleEndian = false; addGlobalMeta("Image width", getSizeX()); addGlobalMeta("Image height", getSizeY()); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
long fp = s.getFilePointer(); s.seek(startFilePointer - 44); int uidLength = s.readInt(); String uid = s.readString(uidLength); s.seek(fp);
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; }
/** * @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ @Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 104; if (!FormatTools.validStream(stream, blockLen, true)) return false; int size = (int) stream.readFloat() * 4; if (size == 0) { stream.seek(0); stream.order(false); size = (int) stream.readFloat() * 4; } stream.skipBytes(4); size *= (int) stream.readFloat(); stream.seek(44); int nsam = (int) stream.readFloat(); size *= nsam; int headerSize = nsam * (int) stream.readFloat() * 4; stream.skipBytes(48); int slices = (int) stream.readFloat(); if (slices > 0) { size *= slices; } return size + headerSize == stream.length() || size == stream.length(); }
/** * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ 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); in.seek(offsets.get(getSeriesCount() - getSeries() - 1)); in.skipBytes(no * FormatTools.getPlaneSize(this)); readPlane(in, x, y, w, h, buf); return buf; }
@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; }
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); } }