/** * Creates a new zip entry taking some information from the given * file and using the provided name. * * <p>The name will be adjusted to end with a forward slash "/" if * the file is a directory. If the file is not a directory a * potential trailing forward slash will be stripped from the * entry name.</p> * @param inputFile file to create the entry from * @param entryName name of the entry */ public ZipArchiveEntry(final File inputFile, final String entryName) { this(inputFile.isDirectory() && !entryName.endsWith("/") ? entryName + "/" : entryName); if (inputFile.isFile()){ setSize(inputFile.length()); } setTime(inputFile.lastModified()); // TODO are there any other fields we can set here? }
/** * Provides default values for compression method and last * modification time. */ private void setDefaults(final ZipArchiveEntry entry) { if (entry.getMethod() == -1) { // not specified entry.setMethod(method); } if (entry.getTime() == -1) { // not specified entry.setTime(System.currentTimeMillis()); } }
zeNew.setComment(ze.getComment()); zeNew.setExtra(ze.getExtra()); zeNew.setTime(ze.getTime());
ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName()); zeOut.setSize(ze.getSize()); zeOut.setTime(ze.getTime()); zos.putArchiveEntry(zeOut); try (final InputStream is = zipEntrySource.getInputStream(ze)) {
current.entry.setTime(time); off += WORD;
@Override public void setTime(long time) { super.setTime(time); }
/** * Creates a new zip entry taking some information from the given * file and using the provided name. * * <p>The name will be adjusted to end with a forward slash "/" if * the file is a directory. If the file is not a directory a * potential trailing forward slash will be stripped from the * entry name.</p> * @param inputFile file to create the entry from * @param entryName name of the entry */ public ZipArchiveEntry(final File inputFile, final String entryName) { this(inputFile.isDirectory() && !entryName.endsWith("/") ? entryName + "/" : entryName); if (inputFile.isFile()){ setSize(inputFile.length()); } setTime(inputFile.lastModified()); // TODO are there any other fields we can set here? }
/** * Provides default values for compression method and last * modification time. */ private void setDefaults(final ZipArchiveEntry entry) { if (entry.getMethod() == -1) { // not specified entry.setMethod(method); } if (entry.getTime() == -1) { // not specified entry.setTime(System.currentTimeMillis()); } }
archiveEntry.setTime(tempNode.lastModified()); zip.putArchiveEntry(archiveEntry); zip.closeArchiveEntry();
zeNew.setComment(ze.getComment()); zeNew.setExtra(ze.getExtra()); zeNew.setTime(ze.getTime()); zos.putArchiveEntry(zeNew); FilterOutputStream fos2 = new FilterOutputStream(zos) {
zeNew.setComment(ze.getComment()); zeNew.setExtra(ze.getExtra()); zeNew.setTime(ze.getTime());
final ZipArchiveEntry entry = new ZipArchiveEntry(source.getPath() + source.getName()); entry.setSize(fileSize); entry.setTime(source.getTimeStamp()); out.putArchiveEntry(entry); } else {
private ZipArchiveEntry filterZipEntry(ZipArchiveEntry entry) { // Set times entry.setCreationTime(FileTime.fromMillis(zipTimestamp)); entry.setLastAccessTime(FileTime.fromMillis(zipTimestamp)); entry.setLastModifiedTime(FileTime.fromMillis(zipTimestamp)); entry.setTime(zipTimestamp); // Remove extended timestamps for (ZipExtraField field : entry.getExtraFields()) { if (field instanceof X5455_ExtendedTimestamp) { entry.removeExtraField(field.getHeaderId()); } } return entry; } }
@Override public void writeEntry( ArchiveOutputStream archiveOutputStream, ArchiveEntry archiveEntry, @Nullable String name, ConsumerWhichThrows<? super OutputStream, ? extends IOException> writeContents ) throws IOException { if (!(archiveOutputStream instanceof ZipArchiveOutputStream)) { throw new IllegalArgumentException(archiveOutputStream.getClass().getName()); } ZipArchiveEntry nzae = new ZipArchiveEntry(name != null ? name : archiveEntry.getName()); nzae.setTime(archiveEntry.getLastModifiedDate().getTime()); if (archiveEntry instanceof ZipArchiveEntry) { ZipArchiveEntry zae = (ZipArchiveEntry) archiveEntry; nzae.setComment(zae.getComment()); nzae.setExternalAttributes(zae.getExternalAttributes()); nzae.setExtraFields(zae.getExtraFields(true)); nzae.setGeneralPurposeBit(zae.getGeneralPurposeBit()); nzae.setInternalAttributes(zae.getInternalAttributes()); nzae.setMethod(zae.getMethod()); if (nzae.isDirectory()) { nzae.setSize(0); nzae.setCrc(0); } } archiveOutputStream.putArchiveEntry(nzae); if (!archiveEntry.isDirectory()) writeContents.consume(archiveOutputStream); archiveOutputStream.closeArchiveEntry(); }
@Override public void writeEntry( ArchiveOutputStream archiveOutputStream, ArchiveEntry archiveEntry, @Nullable String name, ConsumerWhichThrows<? super OutputStream, ? extends IOException> writeContents ) throws IOException { if (!(archiveOutputStream instanceof ZipArchiveOutputStream)) { throw new IllegalArgumentException(archiveOutputStream.getClass().getName()); } ZipArchiveEntry nzae = new ZipArchiveEntry(name != null ? name : archiveEntry.getName()); nzae.setTime(archiveEntry.getLastModifiedDate().getTime()); if (archiveEntry instanceof ZipArchiveEntry) { ZipArchiveEntry zae = (ZipArchiveEntry) archiveEntry; nzae.setComment(zae.getComment()); nzae.setExternalAttributes(zae.getExternalAttributes()); nzae.setExtraFields(zae.getExtraFields(true)); nzae.setGeneralPurposeBit(zae.getGeneralPurposeBit()); nzae.setInternalAttributes(zae.getInternalAttributes()); nzae.setMethod(zae.getMethod()); if (nzae.isDirectory()) { nzae.setSize(0); nzae.setCrc(0); } } archiveOutputStream.putArchiveEntry(nzae); if (!archiveEntry.isDirectory()) writeContents.consume(archiveOutputStream); archiveOutputStream.closeArchiveEntry(); }
ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName()); zeOut.setSize(ze.getSize()); zeOut.setTime(ze.getTime()); zos.putArchiveEntry(zeOut); try (final InputStream is = zipEntrySource.getInputStream(ze)) {
@Override public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) { boolean isDir = r.getResource().isDirectory(); ZipArchiveEntry ent = new ZipArchiveEntry(r.getName()); ent.setTime(round(r.getResource().getLastModified(), 2000)); ent.setSize(isDir ? 0 : r.getResource().getSize()); if (!isDir && r.getCollectionFlags().hasModeBeenSet()) { ent.setUnixMode(r.getCollectionFlags().getMode()); } else if (isDir && r.getCollectionFlags().hasDirModeBeenSet()) { ent.setUnixMode(r.getCollectionFlags().getDirMode()); } else if (r.getResourceFlags().hasModeBeenSet()) { ent.setUnixMode(r.getResourceFlags().getMode()); } else { ent.setUnixMode(isDir ? ArchiveFileSet.DEFAULT_DIR_MODE : ArchiveFileSet.DEFAULT_FILE_MODE); } if (r.getResourceFlags().getZipExtraFields() != null) { ent.setExtraFields(r.getResourceFlags() .getZipExtraFields()); } if (keepCompression && r.getResourceFlags().hasCompressionMethod()) { ent.setMethod(r.getResourceFlags() .getCompressionMethod()); } return ent; } });
current.entry.setTime(time); off += WORD;