Class BZip2CompressorOutputStream

java.lang.Object
java.io.OutputStream
org.jboss.shrinkwrap.impl.base.io.tar.bzip.BZip2CompressorOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BZip2CompressorOutputStream extends OutputStream
An output stream that compresses into the BZip2 format into another stream.

The compression requires large amounts of memory. Thus you should call the close() method as soon as possible, to force BZip2CompressorOutputStream to release the allocated memory.

You can shrink the amount of allocated memory and maybe raise the compression speed by choosing a lower block size, which in turn may cause a lower compression ratio. You can avoid unnecessary memory allocation by avoiding using a block size which is bigger than the size of the input.

You can compute the memory usage for compressing by the following formula:

<code>400k + (9 * block size)</code>.

To get the memory required for decompression by BZip2CompressorInputStream use

<code>65k + (5 * block size)</code>.
Memory usage by block size
Block size Compression
memory usage
Decompression
memory usage
100k 1300k 565k
200k 2200k 1065k
300k 3100k 1565k
400k 4000k 2065k
500k 4900k 2565k
600k 5800k 3065k
700k 6700k 3565k
800k 7600k 4065k
900k 8500k 4565k

For decompression BZip2CompressorInputStream allocates less memory if the bzipped input is smaller than one block.

Instances of this class are not thread safe.

TODO: Update to BZip2 1.0.1

Forked from Apache Commons-Compress with possible changes