/** * Returns <code>true</code> if the given object is an <code>ArchiveEntry</code> whose path is equal to this one, * according to {@link PathUtils#pathEquals(String, String, String)} (trailing slash-insensitive comparison). * * @param o the object to test * @return <code>true</code> if the given object is an <code>ArchiveEntry</code> whose path is equal to this one * @see PathUtils#pathEquals(String, String, String) */ public boolean equals(Object o) { if(!(o instanceof ArchiveEntry)) return false; return PathUtils.pathEquals(getPath(), ((ArchiveEntry)o).getPath(), "/"); }
/** * This method is overridden to return a hash code that is consistent with {@link #equals(Object)}, * so that <code>url1.equals(url2)</code> implies <code>url1.hashCode()==url2.hashCode()</code>. */ public int hashCode() { if(hashCode!=0) // Return any previously computed hashCode. Note that setPath invalidates the hashCode. return hashCode; String path = getPath(); // #equals(Object) is trailing separator insensitive, so the hashCode must be trailing separator invariant hashCode = path.endsWith("/") ?path.substring(0, path.length()-1).hashCode() :path.hashCode(); return hashCode; } }
/** * Extracts this entry's filename from its path and returns it. * * @return this entry's filename */ public String getName() { String path = getPath(); int len = path.length(); // Remove trailing '/' if any if(path.charAt(len-1)=='/') path = path.substring(0, --len); int lastSlash = path.lastIndexOf('/'); return lastSlash==-1? path: path.substring(lastSlash+1, len); }
/** * Shorthand for {@link #getArchiveEntryFile(String)} called with the given entry's path. * * @param entry an entry contained by this archive * @return an AbstractFile that corresponds to the given entry * @throws IOException if neither the entry nor its parent exist within the archive * @throws UnsupportedFileOperationException if {@link FileOperation#READ_FILE} operations are not supported by the * underlying file protocol. */ public AbstractFile getArchiveEntryFile(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { return getArchiveEntryFile(entry.getPath()); }
/** * Returns the depth of this entry based on the number of path delimiters ('/') its path contains. * Top-level entries have a depth of 1. * * @return the depth of this entry */ public int getDepth() { return getDepth(getPath()); }
/** * Returns the relative path of this entry, with respect to the archive file. The path separator of the returned * path is the one returned by {@link #getSeparator()}. As a relative path, the returned path does not start * with a separator character. * * @return the relative path of this entry, with respect to the archive file. */ public String getRelativeEntryPath() { String path = entry.getPath(); // Replace all occurrences of the entry's separator by the archive file's separator, only if the separator is // not "/" (i.e. the entry path separator). String separator = getSeparator(); if(!separator.equals("/")) path = path.replace("/", separator); return path; }
@Override public synchronized InputStream getEntryInputStream(ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException { try { checkRarFile(); } catch (RarException e) { throw new IOException(); } try { return rarFile.getEntryInputStream(entry.getPath().replace('/', '\\')); } catch (RarException e) { throw new IOException(); } } }
public void run(){ MuArchiveExtractCallback extractCallbackSpec = new MuArchiveExtractCallback(cbb.getOutputStream(), entry.getPath()); extractCallbackSpec.Init(sevenZipFile); try { sevenZipFile.Extract(arrays, 1, IInArchive.NExtract_NAskMode_kExtract , extractCallbackSpec); } catch (Exception e) { e.printStackTrace(); // return; } } }
@Override public InputStream getEntryInputStream(ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException { // Will throw an IOException if the file designated by the entry doesn't exist return FileFactory.getFile(((LstArchiveEntry)entry).getBaseFolder()+entry.getPath(), true).getInputStream(); } }
/** * 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); }
if(PathUtils.pathEquals(((ArchiveEntry)childNode.getUserObject()).getPath(), subPath, "/")) {
/** * 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); } }
/** * Creates and returns a {@link com.mucommander.commons.file.archive.zip.provider.ZipEntry} instance using the attributes * of the given {@link ArchiveEntry}. * * @param entry the object that serves to initialize the attributes of the returned ZipEntry * @return a ZipEntry whose attributes are fetched from the given ZipEntry */ private ZipEntry createZipEntry(ArchiveEntry entry) { boolean isDirectory = entry.isDirectory(); String path = entry.getPath(); if(isDirectory && !path.endsWith("/")) path += "/"; com.mucommander.commons.file.archive.zip.provider.ZipEntry zipEntry = new com.mucommander.commons.file.archive.zip.provider.ZipEntry(path); zipEntry.setMethod(ZipConstants.DEFLATED); zipEntry.setTime(System.currentTimeMillis()); zipEntry.setUnixMode(SimpleFilePermissions.padPermissions(entry.getPermissions(), isDirectory ? FilePermissions.DEFAULT_DIRECTORY_PERMISSIONS : FilePermissions.DEFAULT_FILE_PERMISSIONS).getIntValue()); return zipEntry; }
String entryPath = entry.getPath();
ArchiveEntryTree tree = rwArchiveFile.getArchiveEntryTree(); if(tree!=null) { DefaultMutableTreeNode node = tree.findEntryNode(entry.getPath()); if(node!=null && node.getChildCount()>0) throw new IOException();
iterator = archiveFile.getEntryIterator(); while((entry = iterator.nextEntry())!=null && getState() != FileJobState.INTERRUPTED) { entryPath = entry.getPath(); if(entryPath.startsWith(selectedEntry.getPath())) { processEntry = true; break; else if(entryPath.equals(selectedEntry.getPath())) { ?entry.getPath() :PathUtils.removeLeadingFragments(entry.getPath(), "/", baseArchiveDepth);