List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry setExtra
public void setExtra(byte[] extra) throws RuntimeException
From source file:at.spardat.xma.xdelta.JarDelta.java
/** * Entry to new name./*from w w w . j av a 2 s.c om*/ * * @param source the source * @param name the name * @return the zip archive entry * @throws ZipException the zip exception */ public static ZipArchiveEntry entryToNewName(ZipArchiveEntry source, String name) throws ZipException { if (source.getName().equals(name)) return new ZipArchiveEntry(source); ZipArchiveEntry ret = new ZipArchiveEntry(name); byte[] extra = source.getExtra(); if (extra != null) { ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ)); } else { ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true))); } ret.setInternalAttributes(source.getInternalAttributes()); ret.setExternalAttributes(source.getExternalAttributes()); ret.setExtraFields(source.getExtraFields(true)); ret.setCrc(source.getCrc()); ret.setMethod(source.getMethod()); ret.setSize(source.getSize()); return ret; }
From source file:at.spardat.xma.xdelta.JarPatcher.java
/** * Entry to new name.//from w w w . j a v a 2 s .c o m * * @param source the source * @param name the name * @return the zip archive entry * @throws ZipException the zip exception */ private ZipArchiveEntry copyEntry(ZipArchiveEntry source) throws ZipException { ZipArchiveEntry ret = new ZipArchiveEntry(source.getName()); byte[] extra = source.getExtra(); if (extra != null) { ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ)); } else { ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true))); } ret.setInternalAttributes(source.getInternalAttributes()); ret.setExternalAttributes(source.getExternalAttributes()); ret.setExtraFields(source.getExtraFields(true)); return ret; }
From source file:org.zuinnote.hadoop.office.format.common.writer.msexcel.internal.EncryptedZipEntrySource.java
public void setInputStream(InputStream is) throws IOException { this.tmpFile = TempFile.createTempFile("hadoopoffice-protected", ".zip"); ZipArchiveInputStream zis = new ZipArchiveInputStream(is); FileOutputStream fos = new FileOutputStream(tmpFile); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos); ZipArchiveEntry ze;//from w w w. java2 s . c om while ((ze = (ZipArchiveEntry) zis.getNextEntry()) != null) { // rewrite zip entries to match the size of the encrypted data (with padding) ZipArchiveEntry zeNew = new ZipArchiveEntry(ze.getName()); zeNew.setComment(ze.getComment()); zeNew.setExtra(ze.getExtra()); zeNew.setTime(ze.getTime()); zos.putArchiveEntry(zeNew); FilterOutputStream fos2 = new FilterOutputStream(zos) { // do not close underlyzing ZipOutputStream @Override public void close() { } }; OutputStream nos; if (this.ciEncoder != null) { // encrypt if needed nos = new CipherOutputStream(fos2, this.ciEncoder); } else { // do not encrypt nos = fos2; } IOUtils.copy(zis, nos); nos.close(); if (fos2 != null) { fos2.close(); } zos.closeArchiveEntry(); } zos.close(); fos.close(); zis.close(); IOUtils.closeQuietly(is); this.zipFile = new ZipFile(this.tmpFile); }