ZipArchiveOutputStream

Reimplementation of java.util.zip.ZipOutputStream that does 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.nio.channels.SeekableByteChannel 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, this means, you don't need to calculate them yourself. Unfortunately this is not possible for the STORED method, here setting the CRC and uncompressed size information is required before putArchiveEntry can be called.

As of Apache Commons Compress 1.3 it transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more than 65536 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.

Constructors

Link copied to clipboard
constructor(out: OutputStream)
Creates a new ZIP OutputStream filtering the underlying stream.
constructor(file: File, zipSplitSize: Long)
Creates a split ZIP Archive.
constructor(channel: SeekableByteChannel)
Creates a new ZIP OutputStream writing to a SeekableByteChannel.

Types

Link copied to clipboard
enum that represents the possible policies for creating Unicode extra fields.

Properties

Link copied to clipboard
Default compression level for deflated entries.
Link copied to clipboard
val DEFLATED: Int = 8
Compression method for deflated entries.
Link copied to clipboard
open var encoding: String
The encoding to use for file names and the file comment.
Link copied to clipboard
val STORED: Int = 0
Compression method for stored entries.

Functions

Link copied to clipboard
open fun addRawArchiveEntry(entry: ZipArchiveEntry, rawStream: InputStream)
Adds an archive entry with a raw input stream.
Link copied to clipboard
Whether this stream is able to write the given entry.
Link copied to clipboard
open fun close()
Closes this output stream and releases any system resources associated with the stream.
Link copied to clipboard
Writes all necessary data for this entry.
Link copied to clipboard
open fun createArchiveEntry(inputFile: File, entryName: String): ArchiveEntry
Creates a new zip entry taking some information from the given file and using the provided name.
Link copied to clipboard
open fun finish()
Finishes the addition of entries to this stream, without closing it.
Link copied to clipboard
open fun flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream.
Link copied to clipboard
open fun getBytesWritten(): Long
Returns the total number of bytes written to this stream.
Link copied to clipboard
open fun isSeekable(): Boolean
This method indicates whether this archive is writing to a seekable stream (i.e., to a random access file).
Link copied to clipboard
Link copied to clipboard
open fun putArchiveEntry(archiveEntry: ArchiveEntry)
Writes the headers for an archive entry to the output stream.
Link copied to clipboard
open fun setComment(comment: String)
Set the file comment.
Link copied to clipboard
Whether to create Unicode Extra Fields.
Link copied to clipboard
Whether to fall back to UTF and the language encoding flag if the file name cannot be encoded using the specified encoding.
Link copied to clipboard
open fun setLevel(level: Int)
Sets the compression level for subsequent entries.
Link copied to clipboard
open fun setMethod(method: Int)
Sets the default compression method for subsequent entries.
Link copied to clipboard
Whether to set the language encoding flag if the file name encoding is UTF-8.
Link copied to clipboard
open fun setUseZip64(mode: Zip64Mode)
Whether Zip64 extensions will be used.
Link copied to clipboard
open fun write(b: Array<Byte>)

open fun write(b: Int)
Writes a byte to the current archive entry.
open fun write(b: Array<Byte>, offset: Int, length: Int)
Writes bytes to ZIP entry.
Link copied to clipboard
open fun writePreamble(preamble: Array<Byte>)
open fun writePreamble(preamble: Array<Byte>, offset: Int, length: Int)
Write preamble data.