/** * 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? }
@Setter public void setSize(long size) { getWrappedObject().setSize(size); } }
@Signature public void __construct(String name, long size) { __wrappedObject = new ZipArchiveEntry(name); getWrappedObject().setSize(size); }
/** * 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; } }
/** * Records whether a Zip64 extra is present and sets the size * information from it if sizes are 0xFFFFFFFF and the entry * doesn't use a data descriptor. */ private void processZip64Extra(final ZipLong size, final ZipLong cSize) { final Zip64ExtendedInformationExtraField z64 = (Zip64ExtendedInformationExtraField) current.entry.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID); current.usesZip64 = z64 != null; if (!current.hasDataDescriptor) { if (z64 != null // same as current.usesZip64 but avoids NPE warning && (cSize.equals(ZipLong.ZIP64_MAGIC) || size.equals(ZipLong.ZIP64_MAGIC)) ) { current.entry.setCompressedSize(z64.getCompressedSize().getLongValue()); current.entry.setSize(z64.getSize().getLongValue()); } else { current.entry.setCompressedSize(cSize.getValue()); current.entry.setSize(size.getValue()); } } }
ze.setSize(bytes.length); ze.setCompressedSize(bytes.length);
private void readDataDescriptor() throws IOException { readFully(wordBuf); ZipLong val = new ZipLong(wordBuf); if (ZipLong.DD_SIG.equals(val)) { // data descriptor with signature, skip sig readFully(wordBuf); val = new ZipLong(wordBuf); } current.entry.setCrc(val.getValue()); // if there is a ZIP64 extra field, sizes are eight bytes // each, otherwise four bytes each. Unfortunately some // implementations - namely Java7 - use eight bytes without // using a ZIP64 extra field - // https://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7073588 // just read 16 bytes and check whether bytes nine to twelve // look like one of the signatures of what could follow a data // descriptor (ignoring archive decryption headers for now). // If so, push back eight bytes and assume sizes are four // bytes, otherwise sizes are eight bytes each. readFully(twoDwordBuf); final ZipLong potentialSig = new ZipLong(twoDwordBuf, DWORD); if (potentialSig.equals(ZipLong.CFH_SIG) || potentialSig.equals(ZipLong.LFH_SIG)) { pushback(twoDwordBuf, DWORD, DWORD); current.entry.setCompressedSize(ZipLong.getValue(twoDwordBuf)); current.entry.setSize(ZipLong.getValue(twoDwordBuf, WORD)); } else { current.entry.setCompressedSize(ZipEightByteInteger.getLongValue(twoDwordBuf)); current.entry.setSize(ZipEightByteInteger.getLongValue(twoDwordBuf, DWORD)); } }
ZipArchiveEntry ze = en.nextElement(); ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName()); zeOut.setSize(ze.getSize()); zeOut.setTime(ze.getTime()); zos.putArchiveEntry(zeOut);
ze.setSize(z64.getSize().getLongValue()); } else if (hasCompressedSize) { z64.setSize(new ZipEightByteInteger(ze.getSize()));
ze.setSize( 0 ); ze.setMethod( ZipArchiveEntry.STORED );
ZipArchiveEntry entry = new ZipArchiveEntry(name); entry.setSize(size); zipOutput.putNextEntry(entry); zipOutput.write(contentOfEntry); zipOutput.closeArchiveEntry();
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
private static ArchiveEntry newTailArchive(String name, byte[] tail) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(tail.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(tail); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length); zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; } }
byte[] zip(byte[] data, String filename) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos); ZipArchiveEntry entry = new ZipArchiveEntry(filename); entry.setSize(data.length); zos.putArchiveEntry(entry); zos.write(data); zos.closeArchiveEntry(); zos.close(); bos.close(); return bos.toByteArray(); }
private static ArchiveEntry newArchive(File file) throws IOException { ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getName()); zipEntry.setSize(file.length()); zipEntry.setCompressedSize(zipEntry.getSize()); zipEntry.setCrc(FileUtils.checksumCRC32(file)); return zipEntry; }
@Override public void addEntry(Archivable arch) throws IOException { final String fn = arch.getFileName(); ZipArchiveEntry entry = new ZipArchiveEntry(fn); byte[] cbytes = arch.getBytes(); entry.setSize(cbytes.length); this.zout.putArchiveEntry(entry); try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) { IOUtils.copy(bis, zout); this.zout.closeArchiveEntry(); } } }