org.apache.commons.compress.archivers.zip

## Class ScatterZipOutputStream

- java.lang.Object
- - org.apache.commons.compress.archivers.zip.ScatterZipOutputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class ScatterZipOutputStream
      extends Object
      implements Closeable

  A ZIP output stream that is optimized for multi-threaded scatter/gather construction of ZIP files.

  The internal data format of the entries used by this class are entirely private to this class and are not part of any public api whatsoever.

  It is possible to extend this class to support different kinds of backing storage, the default implementation only supports file-based backing.

  Thread safety: This class supports multiple threads. But the "writeTo" method must be called by the thread that originally created the `ZipArchiveEntry`.

  Since:
    1.10

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ScatterZipOutputStream.ZipEntryWriter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ScatterZipOutputStream(ScatterGatherBackingStore backingStore, StreamCompressor streamCompressor)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addArchiveEntry(ZipArchiveEntryRequest zipArchiveEntryRequest)` Adds an archive entry to this scatter stream.
    `void` | `close()` Closes this stream, freeing all resources involved in the creation of this stream.
    `static ScatterZipOutputStream` | `fileBased(File file)` Creates a `ScatterZipOutputStream` with default compression level that is backed by a file
    `static ScatterZipOutputStream` | `fileBased(File file, int compressionLevel)` Creates a `ScatterZipOutputStream` that is backed by a file
    `static ScatterZipOutputStream` | `pathBased(Path path)` Creates a `ScatterZipOutputStream` with default compression level that is backed by a file
    `static ScatterZipOutputStream` | `pathBased(Path path, int compressionLevel)` Creates a `ScatterZipOutputStream` that is backed by a file
    `void` | `writeTo(ZipArchiveOutputStream target)` Writes the contents of this scatter stream to a target archive.
    `ScatterZipOutputStream.ZipEntryWriter` | `zipEntryWriter()` Gets a ZIP entry writer for this scatter stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ScatterZipOutputStream

          public ScatterZipOutputStream(ScatterGatherBackingStore backingStore,
                                        StreamCompressor streamCompressor)

  - ### Method Detail

    - #### fileBased

          public static ScatterZipOutputStream fileBased(File file)
                                                  throws FileNotFoundException

      Creates a `ScatterZipOutputStream` with default compression level that is backed by a file
      Parameters:
        `file` - The file to offload compressed data into.
      Returns:
        A ScatterZipOutputStream that is ready for use.
      Throws:
        `FileNotFoundException` - if the file cannot be found

    - #### fileBased

          public static ScatterZipOutputStream fileBased(File file,
                                                         int compressionLevel)
                                                  throws FileNotFoundException

      Creates a `ScatterZipOutputStream` that is backed by a file
      Parameters:
        `file` - The file to offload compressed data into.
        `compressionLevel` - The compression level to use, @see #Deflater
      Returns:
        A ScatterZipOutputStream that is ready for use.
      Throws:
        `FileNotFoundException` - if the file cannot be found

    - #### pathBased

          public static ScatterZipOutputStream pathBased(Path path)
                                                  throws FileNotFoundException

      Creates a `ScatterZipOutputStream` with default compression level that is backed by a file
      Parameters:
        `path` - The path to offload compressed data into.
      Returns:
        A ScatterZipOutputStream that is ready for use.
      Throws:
        `FileNotFoundException` - if the path cannot be found
      Since:
        1.22

    - #### pathBased

          public static ScatterZipOutputStream pathBased(Path path,
                                                         int compressionLevel)
                                                  throws FileNotFoundException

      Creates a `ScatterZipOutputStream` that is backed by a file
      Parameters:
        `path` - The path to offload compressed data into.
        `compressionLevel` - The compression level to use, @see #Deflater
      Returns:
        A ScatterZipOutputStream that is ready for use.
      Throws:
        `FileNotFoundException` - if the path cannot be found
      Since:
        1.22

    - #### addArchiveEntry

          public void addArchiveEntry(ZipArchiveEntryRequest zipArchiveEntryRequest)
                               throws IOException

      Adds an archive entry to this scatter stream.
      Parameters:
        `zipArchiveEntryRequest` - The entry to write.
      Throws:
        `IOException` - If writing fails

    - #### close

          public void close()
                     throws IOException

      Closes this stream, freeing all resources involved in the creation of this stream.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException` - If closing fails

    - #### writeTo

          public void writeTo(ZipArchiveOutputStream target)
                       throws IOException

      Writes the contents of this scatter stream to a target archive.
      Parameters:
        `target` - The archive to receive the contents of this `ScatterZipOutputStream`.
      Throws:
        `IOException` - If writing fails
      See Also:
        `zipEntryWriter()`

    - #### zipEntryWriter

          public ScatterZipOutputStream.ZipEntryWriter zipEntryWriter()
                                                               throws IOException

      Gets a ZIP entry writer for this scatter stream.
      Returns:
        the ZipEntryWriter created on first call of the method
      Throws:
        `IOException` - If getting scatter stream input stream

Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.