/*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 initCatalog() throws IOException { if (catalog == null) { Entry catalog = root.getChildEntry("Catalog"); if (catalog.length() <= 16L) { // TODO: Throw exception? Return empty catalog? } this.catalog = Catalog.read(catalog.getInputStream()); } }
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 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 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()); } }
private void initCatalog() throws IOException { if (catalog == null) { Entry catalog = root.getChildEntry("Catalog"); if (catalog.length() <= 16L) { // TODO: Throw exception? Return empty catalog? } this.catalog = Catalog.read(catalog.getInputStream()); } }
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); }
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 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()); }