/*public*/ Entry getEntry(String pPath) throws IOException { if (StringUtil.isEmpty(pPath) || !pPath.startsWith("/")) { throw new IllegalArgumentException("Path must be absolute, and contain a valid path: " + pPath); } Entry entry = getRootEntry(); if (pPath.equals("/")) { // '/' means root entry return entry; } else { // Otherwise get children recursively: String[] pathElements = StringUtil.toStringArray(pPath, "/"); for (String pathElement : pathElements) { entry = entry.getChildEntry(pathElement); // No such child... if (entry == null) { break;// TODO: FileNotFoundException? Should behave like Entry.getChildEntry!! } } return entry; } }
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(expected = UnsupportedOperationException.class) public void testChildEntriesUnmodifiable() throws IOException { try (CompoundDocument document = createTestDocument()) { Entry root = document.getRootEntry(); assertNotNull(root); SortedSet<Entry> children = root.getChildEntries(); // Should not be allowed, as it modifies the internal structure children.remove(children.first()); } }
@Test public void testContents() throws IOException { try (CompoundDocument document = createTestDocument()) { Entry root = document.getRootEntry(); assertNotNull(root); SortedSet<Entry> children = new TreeSet<Entry>(root.getChildEntries()); assertEquals(25, children.size()); // Weirdness in the file format, name is *written backwards* 1-24 + Catalog for (String name : "1,2,3,4,5,6,7,8,9,01,02,11,12,21,22,31,32,41,42,51,61,71,81,91,Catalog".split(",")) { assertEquals(name, children.first().getName()); children.remove(children.first()); } } }
@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()); }
Entry root = getRootEntry(); if (shortStreamSIdChain == null) { shortStreamSIdChain = getSIdChain(root.startSId, root.streamSize);
@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 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 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 testReadThumbsCatalogFile() throws IOException { try (CompoundDocument document = createTestDocument()) { 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 testRoot() throws IOException { try (CompoundDocument document = createTestDocument()) { Entry root = document.getRootEntry(); assertNotNull(root); assertEquals("Root Entry", root.getName()); assertTrue(root.isRoot()); assertFalse(root.isFile()); assertFalse(root.isDirectory()); assertEquals(0, root.length()); assertNull(root.getInputStream()); } }
CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input)); Entry entry = document.getRootEntry().getChildEntries().first();
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()); }
@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 testReadThumbsCatalogFile() throws IOException { CompoundDocument document = createTestDocument(); 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 testRoot() throws IOException { CompoundDocument document = createTestDocument(); Entry root = document.getRootEntry(); assertNotNull(root); assertEquals("Root Entry", root.getName()); assertTrue(root.isRoot()); assertFalse(root.isFile()); assertFalse(root.isDirectory()); assertEquals(0, root.length()); assertNull(root.getInputStream()); }