private ImageInputStream createImageInputStream(InputStream is) throws IOException { if (this.cacheDir != null) { return new FileCacheImageInputStream(is, this.cacheDir); } else { return new MemoryCacheImageInputStream(is); } }
private ImageInputStream createImageInputStream(InputStream is) throws IOException { if (this.cacheDir != null) { return new FileCacheImageInputStream(is, this.cacheDir); } else { return new MemoryCacheImageInputStream(is); } }
ImageInputStream iis = new MemoryCacheImageInputStream(bis); try { Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); bis.reset(); iis.close(); iis = new MemoryCacheImageInputStream(bis);
/** * Methods to create a {@link ImageInputStream} out of a byte array. Gets called over and over * because just marking the stream and resetting it was not working against some sample * GeoPackage files, and the result was not finding the readers to use * * @param data * @return */ ImageInputStream getImageInputStream(byte[] data) { ByteArrayInputStream bis = new ByteArrayInputStream(data); return new MemoryCacheImageInputStream(bis); } }
@Override public ImageInputStream createInputStreamInstance(Object input, boolean useCache, File cacheDir) throws IOException { if (input instanceof byte[]) { return new MemoryCacheImageInputStream(new ByteArrayInputStream((byte[]) input)); } return null; }
protected InputStream makeInputStream(byte[] pBytes) { return new IIOInputStreamAdapter(new MemoryCacheImageInputStream(new ByteArrayInputStream(pBytes)), pBytes.length); }
private CompoundDirectory getExif() throws IOException { List<Application> exifSegments = getAppSegments(JPEG.APP1, "Exif"); if (!exifSegments.isEmpty()) { Application exif = exifSegments.get(0); InputStream data = exif.data(); if (data.read() == -1) { // Read pad processWarningOccurred("Exif chunk has no data."); } else { ImageInputStream stream = new MemoryCacheImageInputStream(data); return (CompoundDirectory) new TIFFReader().read(stream); // TODO: Directory offset of thumbnail is wrong/relative to container stream, causing trouble for the TIFFReader... } } return null; }
final MemoryCacheImageInputStream in = new MemoryCacheImageInputStream(encoded); long nextCommand; long prevCommand = -1;
private BufferedImage readJPEG() throws IOException { // IFD1 should contain JPEG offset for JPEG thumbnail Entry jpegOffset = ifd.getEntryById(TIFF.TAG_JPEG_INTERCHANGE_FORMAT); if (jpegOffset != null) { stream.seek(((Number) jpegOffset.getValue()).longValue()); InputStream input = IIOUtil.createStreamAdapter(stream); // For certain EXIF files (encoded with TIFF.TAG_YCBCR_POSITIONING = 2?), we need // EXIF information to read the thumbnail correctly (otherwise the colors are messed up). // Probably related to: http://bugs.sun.com/view_bug.do?bug_id=4881314 // HACK: Splice empty EXIF information into the thumbnail stream byte[] fakeEmptyExif = { // SOI (from original data) (byte) input.read(), (byte) input.read(), // APP1 + len (016) + 'Exif' + 0-term + pad (byte) 0xFF, (byte) 0xE1, 0, 16, 'E', 'x', 'i', 'f', 0, 0, // Big-endian BOM (MM), TIFF magic (042), offset (0000) 'M', 'M', 0, 42, 0, 0, 0, 0, }; input = new SequenceInputStream(new ByteArrayInputStream(fakeEmptyExif), input); try { try (MemoryCacheImageInputStream stream = new MemoryCacheImageInputStream(input)) { return readJPEGThumbnail(reader, stream); } } finally { input.close(); } } throw new IIOException("Missing JPEGInterchangeFormat tag for JPEG compressed EXIF thumbnail"); }
private void initReader(final int pIndex) throws IOException { init(); String name = catalog.getStreamName(pIndex); Entry entry = root.getChildEntry(name); // TODO: It might be possible to speed this up, with less wrapping... // Use in-memory input stream for max speed, images are small ImageInputStream input = new MemoryCacheImageInputStream(entry.getInputStream()); input.skipBytes(THUMBNAIL_OFFSET); reader.setInput(input); }
@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()); }
@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()); }
try (ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream()))
@Test public void testSeekBeforeStream() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9); assertEquals("Should not skip backwards", 0, stream.skip(-5)); assertEquals(10, input.getStreamPosition()); } }
@Test public void testSeekBeforeStreamNoEnd() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input); assertEquals("Should not skip backwards", 0, stream.skip(-5)); assertEquals(10, input.getStreamPosition()); }
return buildPathFromPhotoshopResources(new MemoryCacheImageInputStream(photoshop.get(0).data()));
@Test public void testReadCatalogImageInputStream() throws IOException { InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); MemoryCacheImageInputStream stream = new MemoryCacheImageInputStream(input); stream.setByteOrder(ByteOrder.LITTLE_ENDIAN); CompoundDocument document = new CompoundDocument(stream); Entry root = document.getRootEntry(); assertNotNull(root); assertEquals(25, root.getChildEntries().size()); Entry catalog = root.getChildEntry("Catalog"); assertNotNull(catalog); assertNotNull("Input stream may not be null", catalog.getInputStream()); } }
@Test public void testReadSubstreamRepositionOnClose() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 10); for (int i = 0; i < 7; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } // Make sure we don't read outside stream boundaries assertTrue(input.getStreamPosition() <= 7); // Make sure underlying stream is positioned at end of substream after close stream.close(); assertEquals(10, input.getStreamPosition()); input.close(); }
@Test public void testReadSubstream() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input, 9); for (int i = 0; i < 9; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } assertEquals("Read value after end of stream", -1, stream.read()); assertEquals("Read value after end of stream", -1, stream.read()); // Make sure we don't read outside stream boundaries assertTrue(input.getStreamPosition() <= 9); input.close(); }
@Test public void testReadSubstreamOpenEnd() throws IOException { byte[] bytes = new byte[20]; MemoryCacheImageInputStream input = new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)); input.seek(10); assertEquals(10, input.getStreamPosition()); IIOInputStreamAdapter stream = new IIOInputStreamAdapter(input); for (int i = 0; i < 10; i++) { assertTrue("Unexpected end of stream", -1 != stream.read()); } assertEquals("Read value after end of stream", -1, stream.read()); assertEquals("Read value after end of stream", -1, stream.read()); // Make sure underlying stream is positioned at end of substream after close stream.close(); assertEquals(20, input.getStreamPosition()); input.close(); }