/** * 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 } } }
/** * Returns the contents of the specified folder entry. * * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the * underlying file protocol. */ protected AbstractFile[] ls(AbstractArchiveEntryFile entryFile, FilenameFilter filenameFilter, FileFilter fileFilter) throws IOException, UnsupportedFileOperationException { // Make sure the entries tree is created and up-to-date checkEntriesTree(); if(!entryFile.isBrowsable()) throw new IOException(); DefaultMutableTreeNode matchNode = entryTreeRoot.findEntryNode(entryFile.getEntry().getPath()); if(matchNode==null) throw new IOException(); return ls(matchNode, entryFile, filenameFilter, fileFilter); }
/** * Adds the given {@link ArchiveEntry} to the entries tree. This method will create the tree if it doesn't already * exist, or re-create it if the archive file has changed since it was last created. * * @param entry the ArchiveEntry to add to the tree * @throws IOException if an error occurred while creating the entries tree * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the * underlying file protocol. */ protected void addToEntriesTree(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { checkEntriesTree(); entryTreeRoot.addArchiveEntry(entry); }
DefaultMutableTreeNode entryNode = entryTreeRoot.findEntryNode(entryPath);
/** * Removes the given {@link ArchiveEntry} from the entries tree. This method will create the tree if it doesn't * already exist, or re-create it if the archive file has changed since it was last created. * * @param entry the ArchiveEntry to remove from the tree * @throws IOException if an error occurred while creating the entries tree * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the * underlying file protocol. */ protected void removeFromEntriesTree(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { checkEntriesTree(); DefaultMutableTreeNode entryNode = entryTreeRoot.findEntryNode(entry.getPath()); if(entryNode!=null) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)entryNode.getParent(); parentNode.remove(entryNode); } }
ArchiveEntryTree tree = rwArchiveFile.getArchiveEntryTree(); if(tree!=null) { DefaultMutableTreeNode node = tree.findEntryNode(entry.getPath()); if(node!=null && node.getChildCount()>0) throw new IOException();