protected final CompoundDocument createTestDocument() throws IOException { URL input = getClass().getResource(SAMPLE_DATA); assertNotNull("Missing test resource!", input); assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); try { return new CompoundDocument(new File(input.toURI())); } catch (URISyntaxException e) { throw new AssertionError(e); } }
private void init() throws IOException { assertInput(); if (root == null) { root = new CompoundDocument(imageInput).getRootEntry(); SortedSet children = root.getChildEntries(); thumbnails = new BufferedImage[children.size() - 1]; initCatalog(); // NOTE: This is usually slower, unless you need all images // TODO: Use as many threads as there are CPU cores? :-) if (loadEagerly) { for (int i = 0; i < thumbnails.length; i++) { initReader(i); ImageReader reader = this.reader; // TODO: If stream was detached, we could probably create a // new reader, then fire this off in a separate thread... thumbnails[i] = reader.read(0, null); } } } }
@Test public void testReadCatalogInputStream() throws IOException { InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); CompoundDocument document = new CompoundDocument(input); 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 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 testReadCatalogSeekableStream() throws IOException { InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input)); 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 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()); }
@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()); } }
private boolean isZipFileEncrypted(File file) throws IOException { // If you pass the File parameter to the CompoundDocument constructor it // opens a file pointer that is not released properly and remains open for // the entire lifetime of the application. Using an InputStream we take // control of the file pointer and release it properly after the check. try (InputStream is = new FileInputStream(file)) { new CompoundDocument(is); return true; } catch (CorruptDocumentException e) { return false; } }
protected final CompoundDocument createTestDocument() throws IOException { URL input = getClass().getResource(SAMPLE_DATA); assertNotNull("Missing test resource!", input); assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); try { return new CompoundDocument(new File(input.toURI())); } catch (URISyntaxException e) { throw new AssertionError(e); } }
protected final CompoundDocument createTestDocument() throws IOException { URL input = getClass().getResource(SAMPLE_DATA); assertNotNull("Missing test resource!", input); assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); try { return new CompoundDocument(new File(input.toURI())); } catch (URISyntaxException e) { throw new AssertionError(e); } }
CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input));
public void testReadThumbsCatalogFile() throws IOException, URISyntaxException { URL input = getClass().getResource("/Thumbs-camera.db"); assertNotNull("Missing test resource!", input); assertEquals("Test resource not a file:// resource", "file", input.getProtocol()); File file = new File(input.toURI()); CompoundDocument document = new CompoundDocument(file); 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()); } }
public void testReadCatalogInputStream() throws IOException { InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); assertNotNull("Missing test resource!", input); CompoundDocument document = new CompoundDocument(input); 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()); }
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 child = root.getChildEntry("Catalog"); assertNotNull("Input stream can never be null", child.getInputStream()); }
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 child = root.getChildEntry("Catalog"); assertNotNull("Input stream can never be null", child.getInputStream()); }
@Test public void testReadCatalogInputStream() throws IOException { InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); CompoundDocument document = new CompoundDocument(input); 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()); }
public void testReadCatalogImageInputStream() throws IOException { InputStream input = getClass().getResourceAsStream("/Thumbs-camera.db"); 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 testReadCatalogSeekableStream() throws IOException { InputStream input = getClass().getResourceAsStream(SAMPLE_DATA); assertNotNull("Missing test resource!", input); CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input)); 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 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()); }
@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()); } }