The compression requires large amounts of memory. Thus you should call the
close() method as soon as possible, to force
CBZip2OutputStream to release the allocated memory.
You can shrink the amount of allocated memory and maybe raise the compression speed by choosing a lower blocksize, which in turn may cause a lower compression ratio. You can avoid unnecessary memory allocation by avoiding using a blocksize which is bigger than the size of the input.
You can compute the memory usage for compressing by the following formula:
<code>400k + (9 * blocksize)</code>.
To get the memory required for decompression by CBZip2InputStream use
<code>65k + (5 * blocksize)</code>.
| Blocksize | 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 CBZip2InputStream allocates less memory if the
bzipped input is smaller than one block.
Instances of this class are not threadsafe.
TODO: Update to BZip2 1.0.1
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private int | |
| private final int | blockSize100k
Always: in the range 0 .. |
| private BlockSort | |
| private int | |
| private int | |
| protected static final int | CLEARMASK
This constant is accessible by subclasses for historical purposes. |
| private int | |
| private final CRC | |
| private int | |
| private CBZip2OutputStream. | data
All memory intensive stuff. |
| protected static final int | DEPTH_THRESH
This constant is accessible by subclasses for historical purposes. |
| protected static final int | GREATER_ICOST
This constant is accessible by subclasses for historical purposes. |
| private static final int[] | INCS
Knuth's increments seem to work better than Incerpi-Sedgewick here. |
| private int | last
Index of the last char in the block, so the block size == last + 1. |
| protected static final int | LESSER_ICOST
This constant is accessible by subclasses for historical purposes. |
| public static final int | MAX_BLOCKSIZE
The maximum supported blocksize |
| public static final int | MIN_BLOCKSIZE
The minimum supported blocksize |
| private int | |
| private int | |
| private OutputStream | |
| protected static final int | QSORT_STACK_SIZE
This constant is accessible by subclasses for historical purposes. |
| private int | |
| protected static final int | SETMASK
This constant is accessible by subclasses for historical purposes. |
| protected static final int | SMALL_THRESH
This constant is accessible by subclasses for historical purposes. |
| protected static final int | WORK_FACTOR
This constant is accessible by subclasses for historical purposes. |
| Access | Constructor and Description |
|---|---|
| public | CBZip2OutputStream(final OutputStream
*
the destination stream. out)Constructs a new |
| public | CBZip2OutputStream(final OutputStream
the destination stream. out, final int the blockSize as 100k units. blockSize)Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public static int | Returns: The blocksize, betweenMIN_BLOCKSIZE and
MAX_BLOCKSIZE both inclusive. For a negative
inputLength this method returns MAX_BLOCKSIZE
always.The length of the data which will be compressed by
inputLength)CBZip2OutputStream.Chooses a blocksize based on the given length of the data to compress. |
| public void | close()
Overrides java. Implements java. |
| private void | |
| private void | |
| protected void | |
| public void | |
| public void | flush()
Overrides java. Implements java. |
| private void | |
| public final int | |
| private static void | hbAssignCodes(final int[] code, final byte[] length, final int minLen, final int maxLen, final int alphaSize)
|
| protected static void | hbMakeCodeLengths(char[]
char[] len, int[] char[] freq, int int alphaSize, int int maxLen)This method is accessible by subclasses for historical purposes. |
| private static void | hbMakeCodeLengths(final byte[] len, final int[] freq, final CBZip2OutputStream.
|
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private int | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public void | write(final int
the b)byte.Implements abstract java. |
| public void | write(final byte[]
the data. buf, int the start offset in the data. offs, final int the number of bytes to write. len)Overrides java. len bytes from the specified byte array
starting at offset off to this output stream.
|
| private void | write0(int b)
Keeps track of the last bytes written and implicitly performs run-length encoding as the first step of the bzip2 algorithm. |
| private void | writeRun()
Writes the current byte to the buffer, run-length encoding it if it has been repeated at least four times (the first step RLEs sequences of four identical bytes). |
| allowableBlockSize | back to summary |
|---|---|
| private final int allowableBlockSize | |
| blockCRC | back to summary |
|---|---|
| private int blockCRC | |
| blockSize100k | back to summary |
|---|---|
| private final int blockSize100k Always: in the range 0 .. 9. The current block size is 100000 * this number. | |
| blockSorter | back to summary |
|---|---|
| private BlockSort blockSorter | |
| bsBuff | back to summary |
|---|---|
| private int bsBuff | |
| bsLive | back to summary |
|---|---|
| private int bsLive | |
| CLEARMASK | back to summary |
|---|---|
| protected static final int CLEARMASK This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| combinedCRC | back to summary |
|---|---|
| private int combinedCRC | |
| crc | back to summary |
|---|---|
| private final CRC crc | |
| currentChar | back to summary |
|---|---|
| private int currentChar | |
| data | back to summary |
|---|---|
| private CBZip2OutputStream. All memory intensive stuff. | |
| DEPTH_THRESH | back to summary |
|---|---|
| protected static final int DEPTH_THRESH This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| GREATER_ICOST | back to summary |
|---|---|
| protected static final int GREATER_ICOST This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| INCS | back to summary |
|---|---|
| private static final int[] INCS Knuth's increments seem to work better than Incerpi-Sedgewick here. Possibly because the number of elems to sort is usually small, typically <= 20.
| |
| last | back to summary |
|---|---|
| private int last Index of the last char in the block, so the block size == last + 1. | |
| LESSER_ICOST | back to summary |
|---|---|
| protected static final int LESSER_ICOST This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| MAX_BLOCKSIZE | back to summary |
|---|---|
| public static final int MAX_BLOCKSIZE The maximum supported blocksize | |
| MIN_BLOCKSIZE | back to summary |
|---|---|
| public static final int MIN_BLOCKSIZE The minimum supported blocksize | |
| nInUse | back to summary |
|---|---|
| private int nInUse | |
| nMTF | back to summary |
|---|---|
| private int nMTF | |
| out | back to summary |
|---|---|
| private OutputStream out | |
| QSORT_STACK_SIZE | back to summary |
|---|---|
| protected static final int QSORT_STACK_SIZE This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. If you are ever unlucky/improbable enough to get a stack overflow whilst sorting, increase the following constant and try again. In practice I have never seen the stack go above 27 elems, so the following limit seems very generous. | |
| runLength | back to summary |
|---|---|
| private int runLength | |
| SETMASK | back to summary |
|---|---|
| protected static final int SETMASK This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| SMALL_THRESH | back to summary |
|---|---|
| protected static final int SMALL_THRESH This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| WORK_FACTOR | back to summary |
|---|---|
| protected static final int WORK_FACTOR This constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it. | |
| CBZip2OutputStream | back to summary |
|---|---|
| public CBZip2OutputStream(final OutputStream out) throws IOException Constructs a new
Attention: The caller is responsible to write the two BZip2 magic
bytes
| |
| CBZip2OutputStream | back to summary |
|---|---|
| public CBZip2OutputStream(final OutputStream out, final int blockSize) throws IOException Constructs a new
Attention: The caller is responsible to write the two BZip2 magic
bytes
| |
| blockSort | back to summary |
|---|---|
| private void blockSort() | |
| bsFinishedWithStream | back to summary |
|---|---|
| private void bsFinishedWithStream() throws IOException | |
| bsPutInt | back to summary |
|---|---|
| private void bsPutInt(final int u) throws IOException | |
| bsPutUByte | back to summary |
|---|---|
| private void bsPutUByte(final int c) throws IOException | |
| bsW | back to summary |
|---|---|
| private void bsW(final int n, final int v) throws IOException | |
| chooseBlockSize | back to summary |
|---|---|
| public static int chooseBlockSize(long inputLength) Chooses a blocksize based on the given length of the data to compress.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources
associated with this stream. The general contract of
| |
| endBlock | back to summary |
|---|---|
| private void endBlock() throws IOException | |
| endCompression | back to summary |
|---|---|
| private void endCompression() throws IOException | |
| finalize | back to summary |
|---|---|
| protected void finalize() throws Throwable Overrides java. Overridden to close the stream.
| |
| finish | back to summary |
|---|---|
| public void finish() throws IOException | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
| |
| generateMTFValues | back to summary |
|---|---|
| private void generateMTFValues() | |
| getBlockSize | back to summary |
|---|---|
| public final int getBlockSize() Returns the blocksize parameter specified at construction time.
| |
| hbAssignCodes | back to summary |
|---|---|
| private static void hbAssignCodes(final int[] code, final byte[] length, final int minLen, final int maxLen, final int alphaSize) | |
| hbMakeCodeLengths | back to summary |
|---|---|
| protected static void hbMakeCodeLengths(char[] len, int[] freq, int alphaSize, int maxLen) This method is accessible by subclasses for historical purposes. If you don't know what it does then you don't need it.
| |
| hbMakeCodeLengths | back to summary |
|---|---|
| private static void hbMakeCodeLengths(final byte[] len, final int[] freq, final CBZip2OutputStream. | |
| init | back to summary |
|---|---|
| private void init() throws IOException | |
| initBlock | back to summary |
|---|---|
| private void initBlock() | |
| moveToFrontCodeAndSend | back to summary |
|---|---|
| private void moveToFrontCodeAndSend() throws IOException | |
| sendMTFValues | back to summary |
|---|---|
| private void sendMTFValues() throws IOException | |
| sendMTFValues0 | back to summary |
|---|---|
| private void sendMTFValues0(final int nGroups, final int alphaSize) | |
| sendMTFValues1 | back to summary |
|---|---|
| private int sendMTFValues1(final int nGroups, final int alphaSize) | |
| sendMTFValues2 | back to summary |
|---|---|
| private void sendMTFValues2(final int nGroups, final int nSelectors) | |
| sendMTFValues3 | back to summary |
|---|---|
| private void sendMTFValues3(final int nGroups, final int alphaSize) | |
| sendMTFValues4 | back to summary |
|---|---|
| private void sendMTFValues4() throws IOException | |
| sendMTFValues5 | back to summary |
|---|---|
| private void sendMTFValues5(final int nGroups, final int nSelectors) throws IOException | |
| sendMTFValues6 | back to summary |
|---|---|
| private void sendMTFValues6(final int nGroups, final int alphaSize) throws IOException | |
| sendMTFValues7 | back to summary |
|---|---|
| private void sendMTFValues7() throws IOException | |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| write | back to summary |
|---|---|
| public void write(final byte[] buf, int offs, final int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |
| write0 | back to summary |
|---|---|
| private void write0(int b) throws IOException Keeps track of the last bytes written and implicitly performs run-length encoding as the first step of the bzip2 algorithm. | |
| writeRun | back to summary |
|---|---|
| private void writeRun() throws IOException Writes the current byte to the buffer, run-length encoding it if it has been repeated at least four times (the first step RLEs sequences of four identical bytes). Flushes the current block before writing data if it is full. "write to the buffer" means adding to data.buffer starting two steps "after" this.last - initially starting at index 1 (not 0) - and updating this.last to point to the last index written minus 1. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final byte[] | |
| pack-priv final int[] | |
| pack-priv final byte[] | |
| pack-priv final int[] | |
| pack-priv final boolean[] | |
| pack-priv final int[] | |
| pack-priv int | origPtr
Index of original line in Burrows-Wheeler table. |
| pack-priv final int[] | |
| pack-priv final byte[] | |
| pack-priv final byte[] | |
| pack-priv final byte[] | |
| pack-priv final int[][] | |
| pack-priv final short[] | |
| pack-priv final int[] | |
| pack-priv final byte[][] | |
| pack-priv final int[][] | |
| pack-priv final boolean[] | |
| pack-priv final char[] | |
| pack-priv final byte[] | |
| pack-priv final int[] |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| block | back to summary |
|---|---|
| pack-priv final byte[] block | |
| fmap | back to summary |
|---|---|
| pack-priv final int[] fmap | |
| generateMTFValues_yy | back to summary |
|---|---|
| pack-priv final byte[] generateMTFValues_yy | |
| heap | back to summary |
|---|---|
| pack-priv final int[] heap | |
| inUse | back to summary |
|---|---|
| pack-priv final boolean[] inUse | |
| mtfFreq | back to summary |
|---|---|
| pack-priv final int[] mtfFreq | |
| origPtr | back to summary |
|---|---|
| pack-priv int origPtr Index of original line in Burrows-Wheeler table. This is the index in fmap that points to the last byte of the original data. | |
| parent | back to summary |
|---|---|
| pack-priv final int[] parent | |
| selector | back to summary |
|---|---|
| pack-priv final byte[] selector | |
| selectorMtf | back to summary |
|---|---|
| pack-priv final byte[] selectorMtf | |
| sendMTFValues2_pos | back to summary |
|---|---|
| pack-priv final byte[] sendMTFValues2_pos | |
| sendMTFValues_code | back to summary |
|---|---|
| pack-priv final int[][] sendMTFValues_code | |
| sendMTFValues_cost | back to summary |
|---|---|
| pack-priv final short[] sendMTFValues_cost | |
| sendMTFValues_fave | back to summary |
|---|---|
| pack-priv final int[] sendMTFValues_fave | |
| sendMTFValues_len | back to summary |
|---|---|
| pack-priv final byte[][] sendMTFValues_len | |
| sendMTFValues_rfreq | back to summary |
|---|---|
| pack-priv final int[][] sendMTFValues_rfreq | |
| sentMTFValues4_inUse16 | back to summary |
|---|---|
| pack-priv final boolean[] sentMTFValues4_inUse16 | |
| sfmap | back to summary |
|---|---|
| pack-priv final char[] sfmap | |
| unseqToSeq | back to summary |
|---|---|
| pack-priv final byte[] unseqToSeq | |
| weight | back to summary |
|---|---|
| pack-priv final int[] weight | |
| Data | back to summary |
|---|---|
| pack-priv Data(int blockSize100k) | |