@Override public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(input, seekForwardOnly, ignoreMetadata); if (imageInput != null) { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); } }
private boolean isPNG(final DirectoryEntry pEntry) throws IOException { long magic; imageInput.seek(pEntry.getOffset()); imageInput.setByteOrder(ByteOrder.BIG_ENDIAN); try { magic = imageInput.readLong(); } finally { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); } return magic == DIB.PNG_MAGIC; }
/** * Creates a read only {@code CompoundDocument}. * * @param input the input to read from * * @throws IOException if an I/O exception occurs while reading the header */ public CompoundDocument(final ImageInputStream input) throws IOException { this.input = notNull(input, "input"); // This implementation only supports little endian (Intel) CompoundDocuments input.setByteOrder(ByteOrder.LITTLE_ENDIAN); // TODO: Might be better to read header on first read operation?! // OTOH: It's also good to be fail-fast, so at least we should make // sure we're reading a valid document readHeader(); }
static boolean canDecodeAs(final Object pSource, final int magic) throws IOException { if (!(pSource instanceof ImageInputStream)) { return false; } ImageInputStream stream = (ImageInputStream) pSource; stream.mark(); try { byte[] bom = new byte[2]; stream.readFully(bom); ByteOrder originalOrder = stream.getByteOrder(); try { if (bom[0] == 'I' && bom[1] == 'I') { stream.setByteOrder(ByteOrder.LITTLE_ENDIAN); } else if (bom[0] == 'M' && bom[1] == 'M') { stream.setByteOrder(ByteOrder.BIG_ENDIAN); } else { return false; } return stream.readUnsignedShort() == magic; } finally { stream.setByteOrder(originalOrder); } } finally { stream.reset(); } }
@Override public boolean canDecodeInput(final Object source) throws IOException { if (!(source instanceof ImageInputStream)) { return false; } ImageInputStream stream = (ImageInputStream) source; stream.mark(); try { ByteOrder originalByteOrder = stream.getByteOrder(); stream.setByteOrder(ByteOrder.LITTLE_ENDIAN); try { return stream.readInt() == DCX.MAGIC; } finally { stream.setByteOrder(originalByteOrder); } } finally { stream.reset(); } }
private void readHeader() throws IOException { if (header == null) { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); header = PCXHeader.read(imageInput); if (DEBUG) { System.err.println("header: " + header); } imageInput.flushBefore(imageInput.getStreamPosition()); } imageInput.seek(imageInput.getFlushedPosition()); }
stream.setByteOrder(pos < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
private void readFileHeader() throws IOException { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); // Read file header imageInput.readUnsignedShort(); // Reserved // Should be same as type as the provider int type = imageInput.readUnsignedShort(); int imageCount = imageInput.readUnsignedShort(); // Read directory directory = Directory.read(type, imageCount, imageInput); }
private void readHeader() throws IOException { assertInput(); if (header == null) { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); header = DCXHeader.read(imageInput); if (DEBUG) { System.err.println("header: " + header); } imageInput.flushBefore(imageInput.getStreamPosition()); } imageInput.seek(imageInput.getFlushedPosition()); }
input.setByteOrder(ByteOrder.LITTLE_ENDIAN); input.setByteOrder(ByteOrder.BIG_ENDIAN);
private void readHeader() throws IOException { if (header == null) { header = HeaderParser.parse(imageInput); imageInput.flushBefore(imageInput.getStreamPosition()); imageInput.setByteOrder(header.getByteOrder()); // For PFM support } else { imageInput.seek(imageInput.getFlushedPosition()); } }
private void readHeader() throws IOException { assertInput(); if (header == null) { // BMP files have Intel origin, always little endian imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); // Read BMP file header byte[] fileHeader = new byte[DIB.BMP_FILE_HEADER_SIZE - 4]; // We'll read the last 4 bytes later imageInput.readFully(fileHeader); if (fileHeader[0] != 'B' || fileHeader[1] != 'M') { throw new IIOException("Not a BMP"); } // Ignore rest of data, it's redundant... pixelOffset = imageInput.readUnsignedInt(); // Read DIB header header = DIBHeader.read(imageInput); } }
@Test public void testArrayIndexOutOfBoundsBufferedReadBug() throws IOException { ImageInputStream input = new BufferedImageInputStream(new MemoryCacheImageInputStream(getClass().getResourceAsStream("/thumbsdb/Thumbs-camera.db"))); input.setByteOrder(ByteOrder.LITTLE_ENDIAN); Entry root = new CompoundDocument(input).getRootEntry(); Entry child = root.getChildEntry("Catalog"); assertNotNull(child); assertNotNull(child.getInputStream()); }
private void readHeader() throws IOException { if (header == null) { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN);
@Test public void testArrayIndexOutOfBoundsBufferedReadBug() throws IOException { // TODO: Create a more straight forward way to prove correctness, for now this is good enough to avoid regression ImageInputStream input = new BufferedImageInputStream(new MemoryCacheImageInputStream(getClass().getResourceAsStream("/Thumbs-camera.db"))); input.setByteOrder(ByteOrder.LITTLE_ENDIAN); Entry root = new CompoundDocument(input).getRootEntry(); Entry catalog = root.getChildEntry("Catalog"); assertNotNull("Catalog should not be null", catalog); assertNotNull("Input stream can never be null", catalog.getInputStream()); }
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(input, seekForwardOnly, ignoreMetadata); iis = (ImageInputStream) input; // Always works if (iis != null) iis.setByteOrder(ByteOrder.LITTLE_ENDIAN); gotHeader = false; }
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) { super.setInput(input, seekForwardOnly, ignoreMetadata); iis = (ImageInputStream) input; // Always works if (iis != null) iis.setByteOrder(ByteOrder.LITTLE_ENDIAN); gotHeader = false; }
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN); stream.setByteOrder(originalByteOrder);
/** * Creates a decoder for the specified input stream. * * @param in TODO */ public SEQDecoder(InputStream in) { this.in = new MemoryCacheImageInputStream(in); this.in.setByteOrder(ByteOrder.BIG_ENDIAN); }
private void readFileHeader() throws IOException { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); // Read file header imageInput.readUnsignedShort(); // Reserved // Should be same as type as the provider int type = imageInput.readUnsignedShort(); int imageCount = imageInput.readUnsignedShort(); // Read directory directory = Directory.read(type, imageCount, imageInput); }