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); } }
/** * 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(); }
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); }
/** * @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); in.seek(offsets[no] + getSizeX() * (getSizeY() - y - h)); for (int row=h-1; row>=0; row--) { in.skipBytes(x); in.read(buf, row*w, w); in.skipBytes(getSizeX() - w - x); } return buf; }
/** * @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(); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = false; findString(DIMENSIONS_STRING); in.skipBytes(DIMENSIONS_STRING.length() + 20); m.sizeX = in.readInt(); m.sizeY = in.readInt(); findString(PIXELS_STRING); pixelOffset = in.getFilePointer() + PIXELS_STRING.length() + 20; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYCZT"; m.pixelType = FormatTools.FLOAT; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this, true); readExtraMetadata(store); readFileInfoMetadata(store); }
private String readDate() throws IOException { final StringBuilder dateTime = new StringBuilder(); dateTime.append(String.valueOf(in.readInt())); // year dateTime.append("-"); int month = in.readInt(); dateTime.append(String.format("%02d", month)); dateTime.append("-"); int day = in.readInt(); dateTime.append(String.format("%02d", day)); dateTime.append("T"); int hour = in.readInt(); dateTime.append(String.format("%02d", hour)); dateTime.append(":"); int minute = in.readInt(); dateTime.append(String.format("%02d", minute)); dateTime.append(":"); in.skipBytes(4); float scanTime = in.readInt() / 100f; dateTime.append(String.format("%02d", (int) scanTime)); addGlobalMeta("Scan time (s)", scanTime); return dateTime.toString(); }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 12; if (!FormatTools.validStream(stream, blockLen, false)) return false; String type = stream.readString(4); stream.skipBytes(4); String format = stream.readString(4); return type.equals(AVI_MAGIC_STRING) && format.equals("AVI "); }
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 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); }
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); }
/** * @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); in.seek(offsets[no] + getSizeX() * (getSizeY() - y - h)); for (int row=h-1; row>=0; row--) { in.skipBytes(x); in.read(buf, row*w, w); in.skipBytes(getSizeX() - w - x); } return buf; }
/** * @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(); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = false; findString(DIMENSIONS_STRING); in.skipBytes(DIMENSIONS_STRING.length() + 20); m.sizeX = in.readInt(); m.sizeY = in.readInt(); findString(PIXELS_STRING); pixelOffset = in.getFilePointer() + PIXELS_STRING.length() + 20; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYCZT"; m.pixelType = FormatTools.FLOAT; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this, true); readExtraMetadata(store); readFileInfoMetadata(store); }
private Object readValue() throws IOException { int blockType = in.readInt(); int dataSize = in.readInt(); switch (blockType) { case TYPE_LONG: return in.readInt(); case TYPE_RATIONAL: return in.readDouble(); case TYPE_ASCII: String s = in.readByteToString(dataSize).trim(); final StringBuilder sb = new StringBuilder(); for (int i=0; i<s.length(); i++) { if (s.charAt(i) >= 10) sb.append(s.charAt(i)); else break; } return sb.toString(); case TYPE_SUBBLOCK: return null; } in.skipBytes(dataSize); return ""; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 12; if (!FormatTools.validStream(stream, blockLen, false)) return false; String type = stream.readString(4); stream.skipBytes(4); String format = stream.readString(4); return type.equals(AVI_MAGIC_STRING) && format.equals("AVI "); }
protected String parseROIString(RandomAccessInputStream s) throws IOException { // String is 0x0008 followed by int length for string+NUL. while (s.getFilePointer() < s.length() - 4 && s.readShort() != 8); if (s.getFilePointer() >= s.length() - 8) return null; int strlen = s.readInt(); if (strlen + s.getFilePointer() > s.length()) return null; // Strip off NUL. String text = null; if (strlen >= 2) { // Don't read NUL LOGGER.debug(" String@{} length={}", s.getFilePointer(), strlen); text = s.readString(strlen-2); s.skipBytes(2); } else { s.skipBytes(strlen); } return text; }
@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); }
public DirectoryEntry(RandomAccessInputStream s) throws IOException { schemaType = s.readString(2); pixelType = s.readInt(); filePosition = s.readLong(); filePart = s.readInt(); compression = s.readInt(); pyramidType = s.readByte(); if (pyramidType == 1) { prestitched = false; } s.skipBytes(1); // reserved s.skipBytes(4); // reserved dimensionCount = s.readInt(); dimensionEntries = new DimensionEntry[dimensionCount]; for (int i=0; i<dimensionEntries.length; i++) { dimensionEntries[i] = new DimensionEntry(s); // invalid dimension found; ignore it and the previous one if (dimensionEntries[i].dimension.length() > 1) { dimensionEntries[i] = null; if (i > 0) { dimensionEntries[i - 1] = null; } } } }
/** * @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; }