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); } } } }
if (!canRead(input, false)) { throw new CorruptDocumentException("Not an OLE 2 Compound Document"); if (skipBytesFully(10) != 10) { throw new CorruptDocumentException(); if (skipBytesFully(4) != 4) { throw new CorruptDocumentException(); if (skipBytesFully(freeSIdLength) != freeSIdLength) { throw new CorruptDocumentException(); seekToSId(masterSATSId, FREE_SID); seekToSId(next, FREE_SID);
createdTimestamp = CompoundDocument.toJavaTimeInMillis(pInput.readLong()); modifiedTimestamp = CompoundDocument.toJavaTimeInMillis(pInput.readLong());
private SortedSet<Entry> getEntriesRecursive(final int pDirectoryId, final Entry pParent, final SortedSet<Entry> pEntries) throws IOException { //System.out.println("pDirectoryId: " + pDirectoryId); Entry entry = getEntry(pDirectoryId, pParent); //System.out.println("entry: " + entry); if (!pEntries.add(entry)) { // TODO: This occurs in some Thumbs.db files, and Windows will // still parse the file gracefully somehow... // Deleting and regenerating the file will remove the cyclic // references, but... How can Windows parse this file? throw new CorruptDocumentException("Cyclic chain reference for entry: " + pDirectoryId); } if (entry.prevDId != FREE_SID) { //System.out.println("prevDId: " + entry.prevDId); getEntriesRecursive(entry.prevDId, pParent, pEntries); } if (entry.nextDId != FREE_SID) { //System.out.println("nextDId: " + entry.nextDId); getEntriesRecursive(entry.nextDId, pParent, pEntries); } return pEntries; }
long pos; if (isShortStream(pStreamSize)) { Entry root = getRootEntry(); if (shortStreamSIdChain == null) { shortStreamSIdChain = getSIdChain(root.startSId, root.streamSize);
/*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; } }
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); } }
public static boolean canRead(final DataInput pInput) { return canRead(pInput, true); }
Entry getEntry(final int pDirectoryId, Entry pParent) throws IOException { Entry entry = Entry.readEntry(new LittleEndianDataInputStream( getDirectoryStreamForDId(pDirectoryId) )); entry.parent = pParent; entry.document = this; return entry; }
SortedSet<Entry> getEntries(final int pDirectoryId, final Entry pParent) throws IOException { return getEntriesRecursive(pDirectoryId, pParent, new TreeSet<Entry>()); }
/** * Returns the children of this {@code Entry}. * * @return a {@code SortedSet} of {@code Entry} objects * @throws java.io.IOException if an I/O exception occurs */ public SortedSet<Entry> getChildEntries() throws IOException { if (children == null) { if (isFile() || rootNodeDId == -1) { children = NO_CHILDREN; } else { // Start at root node in R/B tree, and read to the left and right, // re-build tree, according to the docs children = Collections.unmodifiableSortedSet(document.getEntries(rootNodeDId, this)); } } return children; }
@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()); } }
long pos; if (isShortStream(pStreamSize)) { Entry root = getRootEntry(); if (mShortStreamSIdChain == null) { mShortStreamSIdChain = getSIdChain(root.startSId, root.streamSize);
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; } }
private SortedSet<Entry> getEntriesRecursive(final int pDirectoryId, final Entry pParent, final SortedSet<Entry> pEntries) throws IOException { //System.out.println("pDirectoryId: " + pDirectoryId); Entry entry = getEntry(pDirectoryId, pParent); //System.out.println("entry: " + entry); if (!pEntries.add(entry)) { // TODO: This occurs in some Thumbs.db files, and Windows will // still parse the file gracefully somehow... // Deleting and regenerating the file will remove the cyclic // references, but... How can Windows parse this file? throw new CorruptDocumentException("Cyclic chain reference for entry: " + pDirectoryId); } if (entry.prevDId != FREE_SID) { //System.out.println("prevDId: " + entry.prevDId); getEntriesRecursive(entry.prevDId, pParent, pEntries); } if (entry.nextDId != FREE_SID) { //System.out.println("nextDId: " + entry.nextDId); getEntriesRecursive(entry.nextDId, pParent, pEntries); } return pEntries; }
boolean canDecode(final ImageInputStream pInput) throws IOException { maybeInitJPEGProvider(); // If this is a OLE 2 CompoundDocument, we could try... // TODO: How do we know it's thumbs.db format (structure), without reading quite a lot? return jpegProvider != null && CompoundDocument.canRead(pInput); }
Entry getEntry(final int pDirectoryId, Entry pParent) throws IOException { Entry entry = Entry.readEntry(new LittleEndianDataInputStream( getDirectoryStreamForDId(pDirectoryId) )); entry.mParent = pParent; entry.mDocument = this; return entry; }