Class ZipArchiveOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable
    Direct Known Subclasses:
    JarArchiveOutputStream


    public class ZipArchiveOutputStream
    extends ArchiveOutputStream
    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 RandomAccessFile when you know that the output is going to go to a file.

    If RandomAccessFile 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(ArchiveEntry) 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(org.apache.commons.compress.archivers.zip.Zip64Mode). If the stream can not user RandomAccessFile and you try to write a ZipArchiveEntry of unknown size then Zip64 extensions will be disabled by default.

    • Field Detail

      • finished

        protected boolean finished
        indicates if this archive is finished. protected for use in Jar implementation
      • DEFLATED

        public static final int DEFLATED
        Compression method for deflated entries.
        See Also:
        Constant Field Values
      • DEFAULT_COMPRESSION

        public static final int DEFAULT_COMPRESSION
        Default compression level for deflated entries.
        See Also:
        Constant Field Values
      • STORED

        public static final int STORED
        Compression method for stored entries.
        See Also:
        Constant Field Values
      • def

        protected final Deflater def
        This Deflater object is used for output.
    • Constructor Detail

      • ZipArchiveOutputStream

        public ZipArchiveOutputStream(OutputStream out)
        Creates a new ZIP OutputStream filtering the underlying stream.
        Parameters:
        out - the outputstream to zip
      • ZipArchiveOutputStream

        public ZipArchiveOutputStream(File file)
                               throws IOException
        Creates a new ZIP OutputStream writing to a File. Will use random access if possible.
        Parameters:
        file - the file to zip to
        Throws:
        IOException - on error