@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 8; if (!FormatTools.validStream(stream, blockLen, false)) return false; return stream.readLong() == MNG_MAGIC_BYTES; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 8; if (!FormatTools.validStream(stream, blockLen, false)) return false; return stream.readLong() == MNG_MAGIC_BYTES; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 8; if (!FormatTools.validStream(stream, blockLen, false)) return false; return stream.readLong() == LIFF_MAGIC_BYTES; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 8; if (!FormatTools.validStream(stream, blockLen, false)) return false; return stream.readLong() == LIFF_MAGIC_BYTES; }
/** * Read a file offset. * For bigTiff, a 64-bit number is read. For other Tiffs, a 32-bit number * is read and possibly adjusted for a possible carry-over from the previous * offset. */ long getNextOffset(long previous) throws IOException { if (bigTiff || fakeBigTiff) { return in.readLong(); } long offset = (previous & ~0xffffffffL) | (in.readUnsignedInt()); // Only adjust the offset if we know that the file is too large for 32-bit // offsets to be accurate; otherwise, we're making the incorrect assumption // that IFDs are stored sequentially. if (offset < previous && offset != 0 && in.length() > Integer.MAX_VALUE) { offset += 0x100000000L; } return offset; }
/** * Read a file offset. * For bigTiff, a 64-bit number is read. For other Tiffs, a 32-bit number * is read and possibly adjusted for a possible carry-over from the previous * offset. */ long getNextOffset(long previous) throws IOException { if (bigTiff || fakeBigTiff) { return in.readLong(); } long offset = (previous & ~0xffffffffL) | (in.readUnsignedInt()); // Only adjust the offset if we know that the file is too large for 32-bit // offsets to be accurate; otherwise, we're making the incorrect assumption // that IFDs are stored sequentially. if (offset < previous && offset != 0 && in.length() > Integer.MAX_VALUE) { offset += 0x100000000L; } return offset; }
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; }
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; }
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(); } } }
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(); } } }
/** Gets the offsets to every IFD in the file. */ public long[] getIFDOffsets() throws IOException { // check TIFF header int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; final List<Long> offsets = new ArrayList<Long>(); long offset = getFirstOffset(); while (offset > 0 && offset < in.length()) { in.seek(offset); offsets.add(offset); int nEntries = bigTiff ? (int) in.readLong() : in.readUnsignedShort(); int entryBytes = nEntries * bytesPerEntry; if (in.getFilePointer() + entryBytes + (bigTiff ? 8 : 4) > in.length()) { // this can easily happen when writing multiple planes to a file break; } in.skipBytes(entryBytes); offset = getNextOffset(offset); } long[] f = new long[offsets.size()]; for (int i=0; i<f.length; i++) { f[i] = offsets.get(i).longValue(); } return f; }
/** Read the next tag. */ private void readTagHeader() throws IOException { tag = in.readShort(); subTag = in.readShort(); nextTag = (version == 2 ? in.readInt() : in.readLong()); fmt = in.readString(4); in.skipBytes(version == 2 ? 4 : 8); }
/** Read the next tag. */ private void readTagHeader() throws IOException { tag = in.readShort(); subTag = in.readShort(); nextTag = (version == 2 ? in.readInt() : in.readLong()); fmt = in.readString(4); in.skipBytes(version == 2 ? 4 : 8); }
public void overwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) throws FormatException, IOException { if (raf == null) { throw new FormatException("Input stream cannot be null"); } int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; raf.seek(offset); long entries = bigTiff ? raf.readLong() : raf.readUnsignedShort(); long overwriteOffset = offset + bytesPerEntry * entries + (bigTiff ? 8 : 2); out.seek(overwriteOffset); writeIntValue(out, nextPointer); }
public void overwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) throws FormatException, IOException { if (raf == null) { throw new FormatException("Input stream cannot be null"); } int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; raf.seek(offset); long entries = bigTiff ? raf.readLong() : raf.readUnsignedShort(); long overwriteOffset = offset + bytesPerEntry * entries + (bigTiff ? 8 : 2); out.seek(overwriteOffset); writeIntValue(out, nextPointer); }
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); }
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); }
TiffIFDEntry readTiffIFDEntry() throws IOException { int entryTag = in.readUnsignedShort(); // Parse the entry's "Type" IFDType entryType; try { entryType = IFDType.get(in.readUnsignedShort()); } catch (EnumException e) { LOGGER.error("Error reading IFD type at: {}", in.getFilePointer()); throw e; } // Parse the entry's "ValueCount" int valueCount = bigTiff ? (int) in.readLong() : in.readInt(); if (valueCount < 0) { throw new RuntimeException("Count of '" + valueCount + "' unexpected."); } int nValueBytes = valueCount * entryType.getBytesPerElement(); int threshhold = bigTiff ? 8 : 4; long offset = nValueBytes > threshhold ? getNextOffset(0) : in.getFilePointer(); return new TiffIFDEntry(entryTag, entryType, valueCount, offset); } }
TiffIFDEntry readTiffIFDEntry() throws IOException { int entryTag = in.readUnsignedShort(); // Parse the entry's "Type" IFDType entryType; try { entryType = IFDType.get(in.readUnsignedShort()); } catch (EnumException e) { LOGGER.error("Error reading IFD type at: {}", in.getFilePointer()); throw e; } // Parse the entry's "ValueCount" int valueCount = bigTiff ? (int) in.readLong() : in.readInt(); if (valueCount < 0) { throw new RuntimeException("Count of '" + valueCount + "' unexpected."); } int nValueBytes = valueCount * entryType.getBytesPerElement(); int threshhold = bigTiff ? 8 : 4; long offset = nValueBytes > threshhold ? getNextOffset(0) : in.getFilePointer(); return new TiffIFDEntry(entryTag, entryType, valueCount, offset); } }
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; } } } }