/** * 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(), "/"); }
@Override public boolean isDirectory() { return entry.isDirectory(); }
/** * Creates this entry as a directory in the associated <code>AbstractArchiveFile</code>. * <p> * Throws a {@link UnsupportedFileOperationException} if if the underlying file does not support the required * read and write {@link FileOperation file operations}. Throws an <code>IOException</code> if this entry * already exists in the archive or if an I/O error occurred. * </p> * * @throws IOException if this entry already exists in the archive or if an I/O error occurred. * @throws UnsupportedFileOperationException if the underlying archive file does not support the required read and * write {@link FileOperation file operations}. */ @Override public void mkdir() throws IOException, UnsupportedFileOperationException { if(entry.exists()) throw new IOException(); AbstractRWArchiveFile rwArchivefile = (AbstractRWArchiveFile)archiveFile; // Update the ArchiveEntry entry.setDirectory(true); entry.setDate(System.currentTimeMillis()); entry.setSize(0); // Add the entry to the archive file rwArchivefile.addEntry(entry); // The entry now exists entry.setExists(true); }
/** * @throws IOException if the entry does not exist within the archive */ @Override public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException { if(!entry.exists()) throw new IOException(); long oldDate = entry.getDate(); entry.setDate(lastModified); boolean success = updateEntryAttributes(); if(!success) { // restore old date if attributes could not be updated entry.setDate(oldDate); throw new IOException(); } }
String entryPath = entry.getPath(); int entryDepth = entry.getDepth(); int slashPos = 0; DefaultMutableTreeNode node = this; for(int d=1; d<=entryDepth; d++) { if(d==entryDepth && !entry.isDirectory()) { entry.setExists(true); // the entry has to exist node.add(new DefaultMutableTreeNode(entry, true)); break; childNode = (DefaultMutableTreeNode)node.getChildAt(c); if(PathUtils.pathEquals(((ArchiveEntry)childNode.getUserObject()).getPath(), subPath, "/")) { if(d==entryDepth) { entry.setExists(true); // the entry has to exist node.add(new DefaultMutableTreeNode(entry, true)); childNode = new DefaultMutableTreeNode(new ArchiveEntry(subPath, true, entry.getDate(), 0, true), true); node.add(childNode); node = childNode;
@Override public InputStream getEntryInputStream(ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException { if(entry.isDirectory()) throw new IOException(); if(currentEntry.getPath().equals(entry.getPath())) { TarEntry tarEntry = (TarEntry)entry.getEntryObject(); if(tarEntry!=null) { TarInputStream tin = createTarStream(tarEntry.getOffset()); throw new IOException("Unknown TAR entry: "+entry.getName());
if(!entry.exists()) throw new IOException(); ArchiveEntryTree tree = rwArchiveFile.getArchiveEntryTree(); if(tree!=null) { DefaultMutableTreeNode node = tree.findEntryNode(entry.getPath()); if(node!=null && node.getChildCount()>0) throw new IOException(); entry.setDirectory(false); entry.setSize(0); entry.setExists(false);
/** * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given * <code>org.apache.tools.tar.TarEntry</code>. * * @param tarEntry the object that serves to initialize the attributes of the returned ArchiveEntry * @return an ArchiveEntry whose attributes are fetched from the given org.apache.tools.tar.TarEntry */ private ArchiveEntry createArchiveEntry(TarEntry tarEntry) { ArchiveEntry entry = new ArchiveEntry(tarEntry.getName(), tarEntry.isDirectory(), tarEntry.getModTime().getTime(), tarEntry.getSize(), true); entry.setPermissions(new SimpleFilePermissions(tarEntry.getMode() & PermissionBits.FULL_PERMISSION_INT)); entry.setOwner(tarEntry.getUserName()); entry.setGroup(tarEntry.getGroupName()); entry.setEntryObject(tarEntry); return entry; }
/** * 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; }
checkZipFile(); ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject(); if(zipEntry==null) // Should not normally happen throw new IOException(); if(currentEntry.getPath().equals(entry.getPath())) { String entryPath = entry.getPath(); return zin; throw new IOException("Unknown Zip entry: "+entry.getName());
iterator = archiveFile.getEntryIterator(); while((entry = iterator.nextEntry())!=null && getState() != FileJobState.INTERRUPTED) { entryPath = entry.getPath(); if(selectedEntry.isDirectory()) { if(entryPath.startsWith(selectedEntry.getPath())) { processEntry = true; break; else if(entryPath.equals(selectedEntry.getPath())) { ?entry.getPath() :PathUtils.removeLeadingFragments(entry.getPath(), "/", baseArchiveDepth);
@Override public void changePermissions(int permissions) throws IOException { if(!entry.exists()) throw new IOException(); FilePermissions oldPermissions = entry.getPermissions(); FilePermissions newPermissions = new SimpleFilePermissions(permissions, oldPermissions.getMask()); entry.setPermissions(newPermissions); boolean success = updateEntryAttributes(); if(!success) // restore old permissions if attributes could not be updated entry.setPermissions(oldPermissions); if(!success) throw new IOException(); } }
/** * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given {@link com.mucommander.commons.file.archive.zip.provider.ZipEntry}. * It is worth noting that the returned entry has the {@link ArchiveEntry#exists exists} flag set to <code>true</code>. * * @param zipEntry the object that serves to initialize the attributes of the returned ArchiveEntry * @return an ArchiveEntry whose attributes are fetched from the given ZipEntry */ static ArchiveEntry createArchiveEntry(ZipEntry zipEntry) { ArchiveEntry entry = new ArchiveEntry(zipEntry.getName(), zipEntry.isDirectory(), zipEntry.getTime(), zipEntry.getSize(), true); if(zipEntry.hasUnixMode()) entry.setPermissions(new SimpleFilePermissions(zipEntry.getUnixMode())); entry.setEntryObject(zipEntry); return entry; }
@Override public void updateEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject(); // Most of the time, the ZipEntry will not be null. However, it can be null in some rare cases, when directory // entries have been created in the entries tree but don't exist in the Zip file. // That is the case when a file entry exists in the Zip file but has no directory entry for the parent. if(zipEntry!=null) { // Entry exists physically in the zip file checkZipFile(); zipEntry.setTime(entry.getDate()); zipEntry.setUnixMode(entry.getPermissions().getIntValue()); // Physically update the entry's attributes in the Zip file zipFile.updateEntry(zipEntry); // Declare the zip file and entries tree up-to-date declareZipFileUpToDate(); declareEntriesTreeUpToDate(); } }
@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(); } }
@Override public ArchiveEntryIterator getEntryIterator() throws IOException { String extension = getCustomExtension() != null ? getCustomExtension() : getExtension(); String name = getName(); if(extension!=null) { // Remove the 'bz2' or 'tbz2' extension from the entry's name switch(extension.toLowerCase()) { case "tbz2": name = name.substring(0, name.length()-4)+"tar"; break; case "bz2": name = name.substring(0, name.length()-4); break; default: } } return new SingleArchiveEntryIterator(new ArchiveEntry("/"+name, false, getDate(), -1, true)); }
int depth = ArchiveEntry.getDepth(entryPath); return getArchiveEntryFile(new ArchiveEntry(entryPath, false, 0, 0, false), parentFile);
@Override public synchronized void deleteEntry(ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry)entry.getEntryObject(); // Most of the time, the ZipEntry will not be null. However, it can be null in some rare cases, when directory // entries have been created in the entries tree but don't exist in the Zip file. // That is the case when a file entry exists in the Zip file but has no directory entry for the parent. if(zipEntry!=null) { // Entry exists physically in the zip file checkZipFile(); // Delete the entry from the zip file (physically) zipFile.deleteEntry(zipEntry); // Remove the ZipEntry object from the AchiveEntry entry.setEntryObject(null); // Declare the zip file and entries tree up-to-date declareZipFileUpToDate(); declareEntriesTreeUpToDate(); } // Else entry doesn't physically exist in the zip file, only in the entries tree // Remove the entry from the entries tree removeFromEntriesTree(entry); }