java.util.zip.ZipOutputStream to handle the extended functionality of this package, especially
internal/external file attributes and extra fields with different layouts for local file data and central directory entries.
This class will try to use java. when it knows that the output is going to go to a file and no split archive shall be
created.
If SeekableByteChannel cannot be used, this implementation will use a Data Descriptor to store size and CRC information for DEFLATED
entries, you don't need to calculate them yourself. Unfortunately, this is not possible for the STORED method, where setting the CRC and
uncompressed size information is required before putArchiveEntry(ZipArchiveEntry) can be called.
As of Apache Commons Compress 1.3, the class transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more
than 65,536 entries in most cases but explicit control is provided via setUseZip64. If the stream can not use SeekableByteChannel and you try to
write a ZipArchiveEntry of unknown size, then Zip64 extensions will be disabled by default.
| Modifier and Type | Class and Description |
|---|---|
| private static class | ZipArchiveOutputStream.CurrentEntry
Structure collecting information for the entry that is currently being written. |
| private static class | |
| public static class | ZipArchiveOutputStream.UnicodeExtraFieldPolicy
enum that represents the possible policies for creating Unicode extra fields. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | |
| private long | cdDiskNumberStart
Disk number start of central directory. |
| private long | cdLength
Length of central directory. |
| private long | cdOffset
Start of central directory. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv static final byte[] | CFH_SIG
central file header signature |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private String | charsetName
The encoding to use for file names and the file comment. |
| private String | comment
The file comment. |
| private final byte[] | |
| private ZipArchiveOutputStream. | createUnicodeExtraFields
whether to create UnicodePathExtraField-s for each entry. |
| pack-priv static final byte[] | DD_SIG
data descriptor signature |
| protected final Deflater | def
This Deflater object is used for output. |
| public static final int | DEFAULT_COMPRESSION
Default compression level for deflated entries. |
| pack-priv static final String | DEFAULT_ENCODING
default encoding for file names and comment. |
| public static final int | DEFLATED
Compression method for deflated entries. |
| public static final int | EFS_FLAG
General purpose flag, which indicates that file names are written in UTF-8. |
| private final List | entries
List of ZipArchiveEntries written so far. |
| private ZipArchiveOutputStream. | entry
Current entry. |
| pack-priv static final byte[] | EOCD_SIG
end of central dir signature |
| private long | eocdLength
Length of end of central directory |
| private boolean | fallbackToUTF8
Whether to encode non-encodable file names as UTF-8. |
| protected boolean | finished
Indicates if this archive is finished. |
| private boolean | hasCompressionLevelChanged
Has the compression level changed when compared to the last entry? |
| private boolean | hasUsedZip64
Whether anything inside this archive has used a ZIP64 feature. |
| private final boolean | isSplitZip
Whether we are creating a split zip |
| private int | level
Compression level for next entry. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv static final byte[] | LFH_SIG
local file header signature |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final byte[] | LZERO
Helper, a 0 as ZipLong. |
| private final Map | metaData
Holds some book-keeping data for each entry. |
| private int | method
Default compression method for next entry. |
| private final Map | numberOfCDInDiskData
Holds the number of Central Directories on each disk, this is used when writing Zip64 End Of Central Directory and End Of Central Directory |
| private static final byte[] | |
| private final OutputStream | |
| public static final int | STORED
Compression method for stored entries. |
| private final StreamCompressor | |
| private boolean | useUTF8Flag
whether to use the general purpose bit flag when writing UTF-8 file names or not. |
| private static final byte[] | ZERO
Helper, a 0 as ZipShort. |
| pack-priv static final byte[] | ZIP64_EOCD_LOC_SIG
ZIP64 end of central dir locator signature |
| pack-priv static final byte[] | ZIP64_EOCD_SIG
ZIP64 end of central dir signature |
| private Zip64Mode | |
| private ZipEncoding | zipEncoding
The ZIP encoding to use for file names and the file comment. |
| Access | Constructor and Description |
|---|---|
| public | ZipArchiveOutputStream(final File
the file to ZIP to file)Creates a new ZIP OutputStream writing to a File. |
| public | ZipArchiveOutputStream(final File
the file that will become the last part of the split archive file, final long maximum size of a single part of the split archive created by this stream. Must be between 64kB and about 4GB. zipSplitSize)Creates a split ZIP Archive. |
| public | ZipArchiveOutputStream(final OutputStream
the outputstream to zip out)Creates a new ZIP OutputStream filtering the underlying stream. |
| public | ZipArchiveOutputStream(final Path
the path to the file that will become the last part of the split archive path, final long maximum size of a single part of the split archive created by this stream. Must be between 64kB and about 4GB. zipSplitSize)Creates a split ZIP Archive. |
| public | ZipArchiveOutputStream(final Path
the file to ZIP to file, final OpenOption... options specifying how the file is opened. options)Creates a new ZIP OutputStream writing to a Path. |
| public | ZipArchiveOutputStream(final SeekableByteChannel
the channel to ZIP to channel)Creates a new ZIP OutputStream writing to a SeekableByteChannel. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addRawArchiveEntry(final ZipArchiveEntry
The archive entry to add entry, final InputStream The raw input stream of a different entry. May be compressed/encrypted. rawStream)Adds an archive entry with a raw input stream. |
| private void | addUnicodeExtraFields(final ZipArchiveEntry ze, final boolean encodable, final ByteBuffer name)
Adds UnicodeExtra fields for name and file comment if mode is ALWAYS or the data cannot be encoded using the configured encoding. |
| public boolean | canWriteEntryData(final ArchiveEntry
the entry to test ae)Overrides org. |
| private boolean | checkIfNeedsZip64(final Zip64Mode effectiveMode)
Verifies the sizes aren't too big in the Zip64Mode.Never case and returns whether the entry would require a Zip64 extra field. |
| public void | close()
Overrides java. Implements java. |
| public void | closeArchiveEntry()
Implements abstract org. |
| private void | closeCopiedEntry(final boolean
This entry is second phase of a 2-phase ZIP creation, size, compressed size and crc are known in ZipArchiveEntry phased)Writes all necessary data for this entry. |
| private void | |
| private void | |
| public ZipArchiveEntry | createArchiveEntry(final File
the file to create the entry from inputFile, final String name to use for the entry entryName)Implements abstract org. |
| public ZipArchiveEntry | Returns: a new instance.path to create the entry from. inputPath, final String name of the entry. entryName, final LinkOption... options indicating how symbolic links are handled. options)Overrides org. |
| private byte[] | |
| private byte[] | createCentralFileHeader(final ZipArchiveEntry
the entry to write ze, final ByteBuffer The encoded name name, final ZipArchiveOutputStream.meta data for this file entryMetaData,Writes the central file header entry. |
| private byte[] | createLocalFileHeader(final ZipArchiveEntry ze, final ByteBuffer name, final boolean encodable, final boolean phased, final long archiveOffset)
|
| protected final void | |
| pack-priv void | destroy()
Closes the underlying stream/file without finishing the archive, the result will likely be a corrupt archive. |
| public void | finish()
Implements abstract org. |
| public void | flush()
Overrides java. Implements java. |
| private void | |
| public long | Returns: the number of written bytesOverrides org. |
| private Zip64Mode | getEffectiveZip64Mode(final ZipArchiveEntry ze)
If the mode is AsNeeded and the entry is a compressed entry of unknown size that gets written to a non-seekable stream then change the default to Never. |
| public String | Returns: null if using the platform's default character encoding.The encoding to use for file names and the file comment. |
| private ZipEncoding | |
| private GeneralPurposeBit | |
| private ByteBuffer | |
| private Zip64ExtendedInformationExtraField | getZip64Extra(final ZipArchiveEntry ze)
Gets the existing ZIP64 extended information extra field or create a new one and add it to the entry. |
| private boolean | handleSizesAndCrc(final long bytesWritten, final long crc, final Zip64Mode effectiveMode)
Ensures the current entry's size and CRC information is set to the values just written, verifies it isn't too big in the Zip64Mode.Never case and returns whether the entry would require a Zip64 extra field. |
| private void | handleZip64Extra(final ZipArchiveEntry ze, final long lfhOffset, final boolean needsZip64Extra)
If the entry needs Zip64 extra information inside the central directory then configure its data. |
| private boolean | hasZip64Extra(final ZipArchiveEntry ze)
Is there a ZIP64 extended information extra field for the entry? |
| public boolean | Returns: true if seekableThis method indicates whether this archive is writing to a seekable stream (i.e., to a random access file). |
| private boolean | |
| private boolean | |
| private void | |
| public void | putArchiveEntry(final ZipArchiveEntry
describes the entry archiveEntry)Implements abstract org. |
| private void | putArchiveEntry(final ZipArchiveEntry
The archiveEntry archiveEntry, final boolean If true size, compressedSize and crc required to be known up-front in the archiveEntry phased)Writes the headers for an archive entry to the output stream. |
| private void | rewriteSizesAndCrc(final boolean actuallyNeedsZip64)
When using random access output, write the local file header and potentially the ZIP64 extra containing the correct CRC and compressed/uncompressed sizes. |
| public void | |
| public void | setCreateUnicodeExtraFields(final ZipArchiveOutputStream.
whether to create Unicode Extra Fields. bWhether to create Unicode Extra Fields. |
| private void | setDefaults(final ZipArchiveEntry entry)
Provides default values for compression method and last modification time. |
| public void | setEncoding(final String
the encoding to use for file names, use null for the platform's default encoding encoding)The encoding to use for file names and the file comment. |
| public void | setFallbackToUTF8(final boolean
whether to fall back to UTF and the language encoding flag if the file name cannot be encoded using the specified encoding. b)Whether to fall back to UTF and the language encoding flag if the file name cannot be encoded using the specified encoding. |
| public void | |
| public void | setMethod(final int
an method)int from java.util.zip.ZipEntrySets the default compression method for subsequent entries. |
| public void | setUseLanguageEncodingFlag(final boolean
whether to set the language encoding flag if the file name encoding is UTF-8 b)Whether to set the language encoding flag if the file name encoding is UTF-8. |
| public void | setUseZip64(final Zip64Mode
Whether Zip64 extensions will be used. mode)Whether Zip64 extensions will be used. |
| private boolean | shouldAddZip64Extra(final ZipArchiveEntry entry, final Zip64Mode mode)
Whether to add a Zip64 extended information extra field to the local file header. |
| private boolean | Returns: true if zip64 End Of Central Directory is needed4.4.1.4 If one of the fields in the end of central directory record is too small to hold required data, the field SHOULD be set to -1 (0xFFFF or 0xFFFFFFFF) and the ZIP64 format record SHOULD be created. |
| private boolean | |
| private void | validateIfZip64IsNeededInEOCD()
If the Zip64 mode is set to never, then all the data in End Of Central Directory should not exceed their limits. |
| private void | validateSizeInformation(final Zip64Mode effectiveMode)
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 int | |
| private int | |
| public void | write(final byte[]
the byte array to write b, final int the start position to write from offset, final int the number of bytes to write length)Overrides java. |
| protected void | |
| private void | |
| protected void | writeCentralFileHeader(final ZipArchiveEntry
the entry to write ze)Writes the central file header entry. |
| private void | |
| protected void | |
| protected void | |
| private void | |
| protected final void | |
| protected final void | writeOut(final byte[]
the byte array to write data, final int the start position to write from offset, final int the number of bytes to write length)Write bytes to output or random access file. |
| public void | |
| public void | writePreamble(final byte[]
data to write preamble, final int the start offset in the data offset, final int the number of bytes to write length)Write preamble data. |
| protected void | writeZip64CentralDirectory()
Writes the "ZIP64 End of central dir record" and "ZIP64 End of central dir locator". |