Class ScatterZipOutputStream
java.lang.Object
org.apache.commons.compress.archivers.zip.ScatterZipOutputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 theZipArchiveEntry
.- Since:
- 1.10
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ScatterGatherBackingStore
private final AtomicBoolean
private final Queue<ScatterZipOutputStream.CompressedEntry>
private final StreamCompressor
-
Constructor Summary
ConstructorsConstructorDescriptionScatterZipOutputStream
(ScatterGatherBackingStore backingStore, StreamCompressor streamCompressor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArchiveEntry
(ZipArchiveEntryRequest zipArchiveEntryRequest) Add an archive entry to this scatter stream.void
close()
Closes this stream, freeing all resources involved in the creation of this stream.static ScatterZipOutputStream
Create aScatterZipOutputStream
with default compression level that is backed by a filestatic ScatterZipOutputStream
Create aScatterZipOutputStream
that is backed by a filevoid
writeTo
(ZipArchiveOutputStream target) Write the contents of this scatter stream to a target archive.Get a zip entry writer for this scatter stream.
-
Field Details
-
items
-
backingStore
-
streamCompressor
-
isClosed
-
zipEntryWriter
-
-
Constructor Details
-
ScatterZipOutputStream
public ScatterZipOutputStream(ScatterGatherBackingStore backingStore, StreamCompressor streamCompressor)
-
-
Method Details
-
addArchiveEntry
Add an archive entry to this scatter stream.- Parameters:
zipArchiveEntryRequest
- The entry to write.- Throws:
IOException
- If writing fails
-
writeTo
Write the contents of this scatter stream to a target archive.- Parameters:
target
- The archive to receive the contents of thisScatterZipOutputStream
.- Throws:
IOException
- If writing fails- See Also:
-
zipEntryWriter
Get 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
-
close
Closes this stream, freeing all resources involved in the creation of this stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If closing fails
-
fileBased
Create aScatterZipOutputStream
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 Create aScatterZipOutputStream
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
-