/** * 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()); } }
/** * Creates a new zip entry with fields taken from the specified zip entry. * * <p>Assumes the entry represents a directory if and only if the * name ends with a forward slash "/".</p> * * @param entry the entry to get fields from * @throws ZipException on error */ public ZipArchiveEntry(final java.util.zip.ZipEntry entry) throws ZipException { super(entry); setName(entry.getName()); final byte[] extra = entry.getExtra(); if (extra != null) { setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils .UnparseableExtraField.READ)); } else { // initializes extra data to an empty byte array setExtra(); } setMethod(entry.getMethod()); this.size = entry.getSize(); }
/** * Update the original {@link ZipArchiveEntry} with sizes/crc * Do not use this methods from threads that did not create the instance itself ! * @return the zipArchiveEntry that is basis for this request */ public ZipArchiveEntry transferToArchiveEntry(){ final ZipArchiveEntry entry = zipArchiveEntryRequest.getZipArchiveEntry(); entry.setCompressedSize(compressedSize); entry.setSize(size); entry.setCrc(crc); entry.setMethod(zipArchiveEntryRequest.getMethod()); return entry; } }
ze.setMethod(ZipArchiveOutputStream.STORED);
private ZipArchiveEntryRequest createEntry( final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier inputStreamSupplier ) throws IOException { // if we re-compress the zip files there is no need to look at the input stream if ( compressAddedZips ) { return createZipArchiveEntryRequest( zipArchiveEntry, inputStreamSupplier ); } // otherwise we should inspect the first four bites to see if the input stream is zip file or not InputStream is = inputStreamSupplier.get(); byte[] header = new byte[4]; try { int read = is.read( header ); int compressionMethod = zipArchiveEntry.getMethod(); if ( isZipHeader( header ) ) { compressionMethod = ZipEntry.STORED; } zipArchiveEntry.setMethod( compressionMethod ); return createZipArchiveEntryRequest( zipArchiveEntry, prependBytesToStream( header, read, is ) ); } catch ( IOException e ) { IOUtil.close( is ); throw e; } }
current.entry.setMethod(ZipShort.getValue(lfhBuf, off)); off += SHORT;
setTime( ze, lastModified ); ze.setMethod( doCompress ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED ); ze.setUnixMode( UnixStat.FILE_FLAG | mode );
private void createDir(final String name) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(bagName + "/" + name); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { return new ByteArrayInputStream(("").getBytes()); } }; addEntry(archiveEntry, supp); }
/** * 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()); } }
private void createFileFromString(final String relPath, final String content) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(bagName + "/" + relPath); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { try { return new ByteArrayInputStream(content.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } }; addEntry(archiveEntry, supp); }
private void createFileFromURL(final String relPath, final String uri) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(bagName + "/" + relPath); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = getInputStreamSupplier(uri); addEntry(archiveEntry, supp); }
entry.setMethod(level);
/** * Creates a new zip entry with fields taken from the specified zip entry. * * <p>Assumes the entry represents a directory if and only if the * name ends with a forward slash "/".</p> * * @param entry the entry to get fields from * @throws ZipException on error */ public ZipArchiveEntry(final java.util.zip.ZipEntry entry) throws ZipException { super(entry); setName(entry.getName()); final byte[] extra = entry.getExtra(); if (extra != null) { setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils .UnparseableExtraField.READ)); } else { // initializes extra data to an empty byte array setExtra(); } setMethod(entry.getMethod()); this.size = entry.getSize(); }
/** * Update the original {@link ZipArchiveEntry} with sizes/crc * Do not use this methods from threads that did not create the instance itself ! * @return the zipArchiveEntry that is basis for this request */ public ZipArchiveEntry transferToArchiveEntry(){ final ZipArchiveEntry entry = zipArchiveEntryRequest.getZipArchiveEntry(); entry.setCompressedSize(compressedSize); entry.setSize(size); entry.setCrc(crc); entry.setMethod(zipArchiveEntryRequest.getMethod()); return entry; } }
ze.setMethod(ZipArchiveOutputStream.STORED);
@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(); }
@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; } });