@Override public synchronized OutputStream addEntry(final ArchiveEntry entry) throws IOException, UnsupportedFileOperationException { checkZipFile(); final ZipEntry zipEntry = createZipEntry(entry); if(zipEntry.isDirectory()) { // Add the new directory entry to the zip file (physically) zipFile.addEntry(zipEntry); // Set the ZipEntry object into the ArchiveEntry entry.setEntryObject(zipEntry); // Declare the zip file and entries tree up-to-date and add the new entry to the entries tree finishAddEntry(entry); return null; } else { // Set the ZipEntry object into the ArchiveEntry entry.setEntryObject(zipEntry); return new FilteredOutputStream(zipFile.addEntry(zipEntry)) { @Override public void close() throws IOException { super.close(); // Declare the zip file and entries tree up-to-date and add the new entry to the entries tree finishAddEntry(entry); } }; } }
@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); }
/** * 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 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; }