public class BZip2CompressorOutputStream extends OutputStream
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
| Modifier and Type | Field and Description |
|---|---|
static int |
BASE_BLOCK_SIZE |
static int |
G_SIZE |
static int |
MAX_ALPHA_SIZE |
static int |
MAX_BLOCK_SIZE
The maximum supported block size == 9.
|
static int |
MAX_CODE_LEN |
static int |
MAX_SELECTORS |
static int |
MIN_BLOCK_SIZE
The minimum supported block size == 1.
|
static int |
N_GROUPS |
static int |
N_ITERS |
static int |
NUM_OVERSHOOT_BYTES |
static int |
RUNA |
static int |
RUNB |
| Constructor and Description |
|---|
BZip2CompressorOutputStream(OutputStream out)
Constructs a new BZip2CompressorOutputStream with a block size of 900k.
|
BZip2CompressorOutputStream(OutputStream out,
int blockSize)
Constructs a new BZip2CompressorOutputStream with specified block size.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
chooseBlockSize(long inputLength)
Chooses a block size based on the given length of the data to compress.
|
void |
close() |
protected void |
finalize()
Overridden to close the stream.
|
void |
finish() |
void |
flush() |
int |
getBlockSize()
Returns the block size parameter specified at construction time.
|
void |
write(byte[] buf,
int offs,
int len) |
void |
write(int b) |
writepublic static final int MIN_BLOCK_SIZE
public static final int MAX_BLOCK_SIZE
public static final int BASE_BLOCK_SIZE
public static final int MAX_ALPHA_SIZE
public static final int MAX_CODE_LEN
public static final int RUNA
public static final int RUNB
public static final int N_GROUPS
public static final int G_SIZE
public static final int N_ITERS
public static final int MAX_SELECTORS
public static final int NUM_OVERSHOOT_BYTES
public BZip2CompressorOutputStream(OutputStream out) throws IOException
out - the destination stream.IOException - if an I/O error occurs in the specified stream.NullPointerException - if out == null.public BZip2CompressorOutputStream(OutputStream out, int blockSize) throws IOException
out - the destination stream.blockSize - the blockSize as 100k units.IOException - if an I/O error occurs in the specified stream.IllegalArgumentException - if (blockSize < 1) || (blockSize > 9).NullPointerException - if out == null.MIN_BLOCK_SIZE,
MAX_BLOCK_SIZEpublic static int chooseBlockSize(long inputLength)
inputLength - The length of the data which will be compressed by
BZip2CompressorOutputStream.MIN_BLOCK_SIZE and
MAX_BLOCK_SIZE both inclusive. For a negative
inputLength this method returns MAX_BLOCK_SIZE
always.public void write(int b)
throws IOException
write in class OutputStreamIOExceptionprotected void finalize()
throws Throwable
public void finish()
throws IOException
IOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic final int getBlockSize()
public void write(byte[] buf,
int offs,
int len)
throws IOException
write in class OutputStreamIOExceptionCopyright © 2024 JBoss by Red Hat. All rights reserved.