private void initDelegate(boolean seekForwardOnly, boolean ignoreMetadata) throws IOException { // JPEGSegmentImageInputStream that filters out/skips bad/unnecessary segments delegate.setInput(imageInput != null ? new JPEGSegmentImageInputStream(new SubImageInputStream(imageInput, Long.MAX_VALUE), new JPEGSegmentStreamWarningDelegate()) : null, seekForwardOnly, ignoreMetadata); }
@Override public void seek(final long pPosition) throws IOException { if (pPosition < getFlushedPosition()) { throw new IndexOutOfBoundsException("pos < flushedPosition"); } stream.seek(startPos + pPosition); streamPos = pPosition; }
@Test public void testWrapUnknownLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(new ImageInputStreamImpl() { @Override public int read() throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public int read(byte[] b, int off, int len) throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public long length() { return -1; } }, 6); assertEquals(-1, stream.length()); }
static Frame read(final int marker, final ImageInputStream data) throws IOException { int length = data.readUnsignedShort(); return read(marker, new SubImageInputStream(data, length), length); }
@Test public void testWraphBeyondWrappedLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(createStream(5), 6); assertEquals(5, stream.length()); }
@Override public void seek(final long pPosition) throws IOException { if (pPosition < getFlushedPosition()) { throw new IndexOutOfBoundsException("pos < flushedPosition"); } stream.seek(startPos + pPosition); streamPos = pPosition; }
public static Scan read(final ImageInputStream data) throws IOException { int length = data.readUnsignedShort(); return read(new SubImageInputStream(data, length), length); }
public void testWrapUnknownLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(new ImageInputStreamImpl() { @Override public int read() throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public int read(byte[] b, int off, int len) throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public long length() { return -1; } }, 6); assertEquals(-1, stream.length()); }
@Override public void seek(final long pPosition) throws IOException { if (pPosition < getFlushedPosition()) { throw new IndexOutOfBoundsException("pos < flushedPosition"); } mStream.seek(mStartPos + pPosition); streamPos = pPosition; }
private ImageReader initReaderDelegate(int compression) throws IOException { ImageReader reader = getImageReaderDelegate(compression); imageInput.seek(pixelOffset); reader.setInput(new SubImageInputStream(imageInput, header.getImageSize())); return reader; }
public void testWrapUnknownLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(new ImageInputStreamImpl() { @Override public int read() throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public int read(byte[] b, int off, int len) throws IOException { throw new UnsupportedOperationException("Method read not implemented"); } @Override public long length() { return -1; } }, 6); assertEquals(-1, stream.length()); }
private ImageReader initPNGReader(final DirectoryEntry pEntry) throws IOException { ImageReader pngReader = getPNGReader(); imageInput.seek(pEntry.getOffset()); // InputStream inputStream = IIOUtil.createStreamAdapter(imageInput, pEntry.getSize()); // ImageInputStream stream = ImageIO.createImageInputStream(inputStream); ImageInputStream stream = new SubImageInputStream(imageInput, pEntry.getSize()); // NOTE: Will throw IOException on later reads if input is not PNG pngReader.setInput(stream); return pngReader; }
public void testWraphBeyondWrappedLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(createStream(5), 6); assertEquals(5, stream.length()); }
private void initIndex(final int imageIndex) throws IOException { checkBounds(imageIndex); if (index != imageIndex) { imageInput.seek(header.getOffset(imageIndex)); index = imageIndex; readerDelegate.setInput(new SubImageInputStream(imageInput, Long.MAX_VALUE)); } }
public void testWraphBeyondWrappedLength() throws IOException { SubImageInputStream stream = new SubImageInputStream(createStream(5), 6); assertEquals(5, stream.length()); }
@Test(expected = IllegalArgumentException.class) public void testCreateNullStream() throws IOException { new SubImageInputStream(null, 1); fail("Expected IllegalArgumentException with null stream"); }
@Test(expected = IllegalArgumentException.class) public void testCreateNegativeLength() throws IOException { new SubImageInputStream(createStream(0), -1); fail("Expected IllegalArgumentException with negative length"); }
PSDResource(final short resourceId, final ImageInputStream input) throws IOException { id = resourceId; name = readPascalString(input); // Skip pad int nameSize = name.length() + 1; if (nameSize % 2 != 0) { input.readByte(); } size = input.readUnsignedInt(); long startPos = input.getStreamPosition(); readData(new SubImageInputStream(input, size)); // NOTE: This should never happen, however it's safer to keep it here for future compatibility if (input.getStreamPosition() != startPos + size) { input.seek(startPos + size); } // Data is even-padded (word aligned) if (size % 2 != 0) { input.read(); } }
PSDImageResource(final short resourceId, final ImageInputStream input) throws IOException { id = resourceId; name = PSDUtil.readPascalString(input); // Skip pad int nameSize = name.length() + 1; if (nameSize % 2 != 0) { input.readByte(); } size = input.readUnsignedInt(); long startPos = input.getStreamPosition(); readData(new SubImageInputStream(input, size)); // NOTE: This should never happen, however it's safer to keep it here to if (input.getStreamPosition() != startPos + size) { input.seek(startPos + size); } // Data is even-padded (word aligned) if (size % 2 != 0) { input.read(); } }
private BufferedImage readForeignFormat(int imageIndex, final ImageReadParam param, final IconResource resource) throws IOException { ImageInputStream stream = new SubImageInputStream(imageInput, resource.length); stream = new SubImageInputStream(imageInput, resource.length);