putLong(ze.getCrc(), buf, CFH_CRC_OFFSET); if (ze.getCompressedSize() >= ZIP64_MAGIC || ze.getSize() >= ZIP64_MAGIC
/** * Adds an archive entry with a raw input stream. * * If crc, size and compressed size are supplied on the entry, these values will be used as-is. * Zip64 status is re-established based on the settings in this stream, and the supplied value * is ignored. * * The entry is put and closed immediately. * * @param entry The archive entry to add * @param rawStream The raw input stream of a different entry. May be compressed/encrypted. * @throws IOException If copying fails */ public void addRawArchiveEntry(final ZipArchiveEntry entry, final InputStream rawStream) throws IOException { final ZipArchiveEntry ae = new ZipArchiveEntry(entry); if (hasZip64Extra(ae)) { // Will be re-added as required. this may make the file generated with this method // somewhat smaller than standard mode, // since standard mode is unable to remove the zip 64 header. ae.removeExtraField(Zip64ExtendedInformationExtraField.HEADER_ID); } final boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN && ae.getSize() != ArchiveEntry.SIZE_UNKNOWN && ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN; putArchiveEntry(ae, is2PhaseSource); copyFromZipInputStream(rawStream); closeCopiedEntry(is2PhaseSource); }
/** * Throws an exception if the size is unknown for a stored entry * that is written to a non-seekable output or the entry is too * big to be written without Zip64 extra but the mode has been set * to Never. */ private void validateSizeInformation(final Zip64Mode effectiveMode) throws ZipException { // Size/CRC not required if SeekableByteChannel is used if (entry.entry.getMethod() == STORED && channel == null) { if (entry.entry.getSize() == ArchiveEntry.SIZE_UNKNOWN) { throw new ZipException("uncompressed size is required for" + " STORED method when not writing to a" + " file"); } if (entry.entry.getCrc() == ZipArchiveEntry.CRC_UNKNOWN) { throw new ZipException("crc checksum is required for STORED" + " method when not writing to a file"); } entry.entry.setCompressedSize(entry.entry.getSize()); } if ((entry.entry.getSize() >= ZIP64_MAGIC || entry.entry.getCompressedSize() >= ZIP64_MAGIC) && effectiveMode == Zip64Mode.Never) { throw new Zip64RequiredException(Zip64RequiredException .getEntryTooBigMessage(entry.entry)); } }
/** * Writes the data descriptor entry. * @param ze the entry to write * @throws IOException on error */ protected void writeDataDescriptor(final ZipArchiveEntry ze) throws IOException { if (!usesDataDescriptor(ze.getMethod(), false)) { return; } writeCounted(DD_SIG); writeCounted(ZipLong.getBytes(ze.getCrc())); if (!hasZip64Extra(ze)) { writeCounted(ZipLong.getBytes(ze.getCompressedSize())); writeCounted(ZipLong.getBytes(ze.getSize())); } else { writeCounted(ZipEightByteInteger.getBytes(ze.getCompressedSize())); writeCounted(ZipEightByteInteger.getBytes(ze.getSize())); } }
writeOut(ZipLong.getBytes(entry.entry.getCrc())); if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) { writeOut(ZipLong.getBytes(entry.entry.getCompressedSize()));
/** * @return The CRC32 (0...0xffffffffL) of the contents of the given archive entry, or -1L if unknown * @deprecated Should be replaced by a new method {@code ArchiveEntry.getCrc32()} */ @Deprecated public static long getEntryCrc32(ArchiveEntry archiveEntry) { if (archiveEntry instanceof ZipArchiveEntry) return ((ZipArchiveEntry) archiveEntry).getCrc(); if (archiveEntry instanceof SevenZArchiveEntry) { SevenZArchiveEntry szae = (SevenZArchiveEntry) archiveEntry; return szae.getHasCrc() ? 0xffffffffL & szae.getCrcValue() : -1; } return -1; }
/** * @return The CRC32 (0...0xffffffffL) of the contents of the given archive entry, or -1L if unknown * @deprecated Should be replaced by a new method {@code ArchiveEntry.getCrc32()} */ @Deprecated public static long getEntryCrc32(ArchiveEntry archiveEntry) { if (archiveEntry instanceof ZipArchiveEntry) return ((ZipArchiveEntry) archiveEntry).getCrc(); if (archiveEntry instanceof SevenZArchiveEntry) { SevenZArchiveEntry szae = (SevenZArchiveEntry) archiveEntry; return szae.getHasCrc() ? 0xffffffffL & szae.getCrcValue() : -1; } return -1; }
putLong(ze.getCrc(), buf, CFH_CRC_OFFSET); if (ze.getCompressedSize() >= ZIP64_MAGIC || ze.getSize() >= ZIP64_MAGIC
/** * Adds an archive entry with a raw input stream. * * If crc, size and compressed size are supplied on the entry, these values will be used as-is. * Zip64 status is re-established based on the settings in this stream, and the supplied value * is ignored. * * The entry is put and closed immediately. * * @param entry The archive entry to add * @param rawStream The raw input stream of a different entry. May be compressed/encrypted. * @throws IOException If copying fails */ public void addRawArchiveEntry(final ZipArchiveEntry entry, final InputStream rawStream) throws IOException { final ZipArchiveEntry ae = new ZipArchiveEntry(entry); if (hasZip64Extra(ae)) { // Will be re-added as required. this may make the file generated with this method // somewhat smaller than standard mode, // since standard mode is unable to remove the zip 64 header. ae.removeExtraField(Zip64ExtendedInformationExtraField.HEADER_ID); } final boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN && ae.getSize() != ArchiveEntry.SIZE_UNKNOWN && ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN; putArchiveEntry(ae, is2PhaseSource); copyFromZipInputStream(rawStream); closeCopiedEntry(is2PhaseSource); }
/** * Throws an exception if the size is unknown for a stored entry * that is written to a non-seekable output or the entry is too * big to be written without Zip64 extra but the mode has been set * to Never. */ private void validateSizeInformation(final Zip64Mode effectiveMode) throws ZipException { // Size/CRC not required if SeekableByteChannel is used if (entry.entry.getMethod() == STORED && channel == null) { if (entry.entry.getSize() == ArchiveEntry.SIZE_UNKNOWN) { throw new ZipException("uncompressed size is required for" + " STORED method when not writing to a" + " file"); } if (entry.entry.getCrc() == ZipArchiveEntry.CRC_UNKNOWN) { throw new ZipException("crc checksum is required for STORED" + " method when not writing to a file"); } entry.entry.setCompressedSize(entry.entry.getSize()); } if ((entry.entry.getSize() >= ZIP64_MAGIC || entry.entry.getCompressedSize() >= ZIP64_MAGIC) && effectiveMode == Zip64Mode.Never) { throw new Zip64RequiredException(Zip64RequiredException .getEntryTooBigMessage(entry.entry)); } }
/** * Writes the data descriptor entry. * @param ze the entry to write * @throws IOException on error */ protected void writeDataDescriptor(final ZipArchiveEntry ze) throws IOException { if (!usesDataDescriptor(ze.getMethod(), false)) { return; } writeCounted(DD_SIG); writeCounted(ZipLong.getBytes(ze.getCrc())); if (!hasZip64Extra(ze)) { writeCounted(ZipLong.getBytes(ze.getCompressedSize())); writeCounted(ZipLong.getBytes(ze.getSize())); } else { writeCounted(ZipEightByteInteger.getBytes(ze.getCompressedSize())); writeCounted(ZipEightByteInteger.getBytes(ze.getSize())); } }
writeOut(ZipLong.getBytes(entry.entry.getCrc())); if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) { writeOut(ZipLong.getBytes(entry.entry.getCompressedSize()));