/** * Creates the entries tree, used by {@link #ls(AbstractArchiveEntryFile , com.mucommander.commons.file.filter.FilenameFilter, com.mucommander.commons.file.filter.FileFilter)} * to quickly list the contents of an archive's subfolder. * * @throws IOException if an error occured while retrieving this archive's entries * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the * underlying file protocol. */ protected void createEntriesTree() throws IOException, UnsupportedFileOperationException { // TODO: this method is not thread-safe and needs to be synchronized ArchiveEntryTree treeRoot = new ArchiveEntryTree(); archiveEntryFiles = new WeakHashMap<ArchiveEntry, AbstractArchiveEntryFile>(); long start = System.currentTimeMillis(); ArchiveEntryIterator entries = getEntryIterator(); try { ArchiveEntry entry; while((entry=entries.nextEntry())!=null) treeRoot.addArchiveEntry(entry); LOGGER.info("entries tree created in "+(System.currentTimeMillis()-start)+" ms"); this.entryTreeRoot = treeRoot; declareEntriesTreeUpToDate(); } finally { try { entries.close(); } catch(IOException e) { // Not much we can do about it } } }
@Override public InputStream getEntryInputStream(ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException { InputStream in = getInputStream(); ArchiveEntryIterator iterator = new ArArchiveEntryIterator(in); ArchiveEntry currentEntry; while((currentEntry = iterator.nextEntry())!=null) { if(currentEntry.getName().equals(entry.getName())) { LOGGER.trace("found entry {}", entry.getName()); return new BoundedInputStream(in, entry.getSize(), false); } } // Entry not found, should not normally happen LOGGER.info("Warning: entry not found, throwing IOException"); throw new IOException(); } }