Top Description Inners Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public Class ScatterZipOutputStream

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .File, .FileNotFoundException, .IOException, .InputStream, java.nio.file.Path, java.util.Iterator, .Queue, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicBoolean, java.util.zip.Deflater, org.apache.commons.compress.parallel.FileBasedScatterGatherBackingStore, .ScatterGatherBackingStore, org.apache.commons.compress.utils.BoundedInputStream

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 and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class

Field Summary

Modifier and TypeField and Description
private final ScatterGatherBackingStore
private final AtomicBoolean
private final Queue<ScatterZipOutputStream.CompressedEntry>
private final StreamCompressor
private ScatterZipOutputStream.ZipEntryWriter

Constructor Summary

AccessConstructor and Description
public
ScatterZipOutputStream(final ScatterGatherBackingStore backingStore, final StreamCompressor streamCompressor)

Method Summary

Modifier and TypeMethod and Description
public void
addArchiveEntry(final ZipArchiveEntryRequest
The entry to write.
zipArchiveEntryRequest
)

Adds an archive entry to this scatter stream.

public void
close()

Implements java.io.Closeable.close.

Closes this stream, freeing all resources involved in the creation of this stream.
public static ScatterZipOutputStream

Returns:

A ScatterZipOutputStream that is ready for use.
fileBased
(final File
The file to offload compressed data into.
file
)

Creates a ScatterZipOutputStream with default compression level that is backed by a file

public static ScatterZipOutputStream

Returns:

A ScatterZipOutputStream that is ready for use.
fileBased
(final File
The file to offload compressed data into.
file
,
final int
The compression level to use, @see #Deflater
compressionLevel
)

Creates a ScatterZipOutputStream that is backed by a file

public static ScatterZipOutputStream

Returns:

A ScatterZipOutputStream that is ready for use.
pathBased
(final Path
The path to offload compressed data into.
path
)

Creates a ScatterZipOutputStream with default compression level that is backed by a file

public static ScatterZipOutputStream

Returns:

A ScatterZipOutputStream that is ready for use.
pathBased
(final Path
The path to offload compressed data into.
path
,
final int
The compression level to use, @see #Deflater
compressionLevel
)

Creates a ScatterZipOutputStream that is backed by a file

public void
writeTo(final ZipArchiveOutputStream
The archive to receive the contents of this ScatterZipOutputStream.
target
)

Writes the contents of this scatter stream to a target archive.

public ScatterZipOutputStream.ZipEntryWriter

Returns:

the ZipEntryWriter created on first call of the method
zipEntryWriter
()

Gets a ZIP entry writer for this scatter stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backingStoreback to summary
private final ScatterGatherBackingStore backingStore
isClosedback to summary
private final AtomicBoolean isClosed
itemsback to summary
private final Queue<ScatterZipOutputStream.CompressedEntry> items
streamCompressorback to summary
private final StreamCompressor streamCompressor
zipEntryWriterback to summary
private ScatterZipOutputStream.ZipEntryWriter zipEntryWriter

Constructor Detail

ScatterZipOutputStreamback to summary
public ScatterZipOutputStream(final ScatterGatherBackingStore backingStore, final StreamCompressor streamCompressor)

Method Detail

addArchiveEntryback to summary
public void addArchiveEntry(final ZipArchiveEntryRequest zipArchiveEntryRequest) throws IOException

Adds an archive entry to this scatter stream.

Parameters
zipArchiveEntryRequest:ZipArchiveEntryRequest

The entry to write.

Exceptions
IOException:
If writing fails
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes this stream, freeing all resources involved in the creation of this stream.

Annotations
@Override
Exceptions
IOException:
If closing fails
fileBasedback to summary
public static ScatterZipOutputStream fileBased(final File file) throws FileNotFoundException

Creates a ScatterZipOutputStream with default compression level that is backed by a file

Parameters
file:File

The file to offload compressed data into.

Returns:ScatterZipOutputStream

A ScatterZipOutputStream that is ready for use.

Exceptions
FileNotFoundException:
if the file cannot be found
fileBasedback to summary
public static ScatterZipOutputStream fileBased(final File file, final int compressionLevel) throws FileNotFoundException

Creates a ScatterZipOutputStream that is backed by a file

Parameters
file:File

The file to offload compressed data into.

compressionLevel:int

The compression level to use, @see #Deflater

Returns:ScatterZipOutputStream

A ScatterZipOutputStream that is ready for use.

Exceptions
FileNotFoundException:
if the file cannot be found
pathBasedback to summary
public static ScatterZipOutputStream pathBased(final Path path) throws FileNotFoundException

Creates a ScatterZipOutputStream with default compression level that is backed by a file

Parameters
path:Path

The path to offload compressed data into.

Returns:ScatterZipOutputStream

A ScatterZipOutputStream that is ready for use.

Exceptions
FileNotFoundException:
if the path cannot be found
Since
1.22
pathBasedback to summary
public static ScatterZipOutputStream pathBased(final Path path, final int compressionLevel) throws FileNotFoundException

Creates a ScatterZipOutputStream that is backed by a file

Parameters
path:Path

The path to offload compressed data into.

compressionLevel:int

The compression level to use, @see #Deflater

Returns:ScatterZipOutputStream

A ScatterZipOutputStream that is ready for use.

Exceptions
FileNotFoundException:
if the path cannot be found
Since
1.22
writeToback to summary
public void writeTo(final ZipArchiveOutputStream target) throws IOException

Writes the contents of this scatter stream to a target archive.

Parameters
target:ZipArchiveOutputStream

The archive to receive the contents of this ScatterZipOutputStream.

Exceptions
IOException:
If writing fails
See Also
zipEntryWriter()
zipEntryWriterback to summary
public ScatterZipOutputStream.ZipEntryWriter zipEntryWriter() throws IOException

Gets a ZIP entry writer for this scatter stream.

Returns:ScatterZipOutputStream.ZipEntryWriter

the ZipEntryWriter created on first call of the method

Exceptions
IOException:
If getting scatter stream input stream
org.apache.commons.compress.archivers.zip back to summary

private final Class ScatterZipOutputStream.CompressedEntry

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.archivers.zip.ScatterZipOutputStream.CompressedEntry

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv final long
pack-priv final long
pack-priv final ZipArchiveEntryRequest

Constructor Summary

AccessConstructor and Description
pack-priv
CompressedEntry(final ZipArchiveEntryRequest zipArchiveEntryRequest, final long crc, final long compressedSize, final long size)

Method Summary

Modifier and TypeMethod and Description
public ZipArchiveEntry

Returns:

the zipArchiveEntry that is the basis for this request.
transferToArchiveEntry
()

Updates the original ZipArchiveEntry with sizes/crc.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

compressedSizeback to summary
pack-priv final long compressedSize
crcback to summary
pack-priv final long crc
sizeback to summary
pack-priv final long size
zipArchiveEntryRequestback to summary
pack-priv final ZipArchiveEntryRequest zipArchiveEntryRequest

Constructor Detail

CompressedEntryback to summary
pack-priv CompressedEntry(final ZipArchiveEntryRequest zipArchiveEntryRequest, final long crc, final long compressedSize, final long size)

Method Detail

transferToArchiveEntryback to summary
public ZipArchiveEntry transferToArchiveEntry()

Updates the original ZipArchiveEntry with sizes/crc. Do not use this method from threads that did not create the instance itself!

Returns:ZipArchiveEntry

the zipArchiveEntry that is the basis for this request.

org.apache.commons.compress.archivers.zip back to summary

public Class ScatterZipOutputStream.ZipEntryWriter

extends Object
implements Closeable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.archivers.zip.ScatterZipOutputStream.ZipEntryWriter
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private final Iterator<ScatterZipOutputStream.CompressedEntry>
private final InputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

itemsIteratorback to summary
private final Iterator<ScatterZipOutputStream.CompressedEntry> itemsIterator
itemsIteratorDataback to summary
private final InputStream itemsIteratorData

Constructor Detail

ZipEntryWriterback to summary
public ZipEntryWriter(final ScatterZipOutputStream scatter) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
writeNextZipEntryback to summary
public void writeNextZipEntry(final ZipArchiveOutputStream target) throws IOException