Class CBZip2OutputStream
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable,- BZip2Constants
 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
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.static final intThe maximum supported blocksize== 9.static final intThe minimum supported blocksize== 1.protected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.protected static final intThis constant is accessible by subclasses for historical purposes.Fields inherited from interface org.apache.tools.bzip2.BZip2ConstantsbaseBlockSize, G_SIZE, MAX_ALPHA_SIZE, MAX_CODE_LEN, MAX_SELECTORS, N_GROUPS, N_ITERS, NUM_OVERSHOOT_BYTES, rNums, RUNA, RUNB
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a newCBZip2OutputStreamwith a blocksize of 900k.CBZip2OutputStream(OutputStream out, int blockSize) Constructs a newCBZip2OutputStreamwith specified blocksize.
- 
Method SummaryModifier and TypeMethodDescriptionstatic intchooseBlockSize(long inputLength) Chooses a blocksize based on the given length of the data to compress.voidclose()protected voidfinalize()Overridden to close the stream.voidfinish()voidflush()final intReturns the blocksize parameter specified at construction time.protected static voidhbMakeCodeLengths(char[] len, int[] freq, int alphaSize, int maxLen) This method is accessible by subclasses for historical purposes.voidwrite(byte[] buf, int offs, int len) voidwrite(int b) Methods inherited from class java.io.OutputStreamnullOutputStream, write
- 
Field Details- 
MIN_BLOCKSIZEpublic static final int MIN_BLOCKSIZEThe minimum supported blocksize== 1.- See Also:
 
- 
MAX_BLOCKSIZEpublic static final int MAX_BLOCKSIZEThe maximum supported blocksize== 9.- See Also:
 
- 
SETMASKprotected static final int SETMASKThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
CLEARMASKprotected static final int CLEARMASKThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
GREATER_ICOSTprotected static final int GREATER_ICOSTThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
LESSER_ICOSTprotected static final int LESSER_ICOSTThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
SMALL_THRESHprotected static final int SMALL_THRESHThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
DEPTH_THRESHprotected static final int DEPTH_THRESHThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
WORK_FACTORprotected static final int WORK_FACTORThis constant is accessible by subclasses for historical purposes. If you don't know what it means then you don't need it.- See Also:
 
- 
QSORT_STACK_SIZEprotected static final int QSORT_STACK_SIZEThis 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. - See Also:
 
 
- 
- 
Constructor Details- 
CBZip2OutputStreamConstructs a newCBZip2OutputStreamwith a blocksize of 900k.Attention: The caller is responsible to write the two BZip2 magic bytes "BZ"to the specified stream prior to calling this constructor.- Parameters:
- out- * the destination stream.
- Throws:
- IOException- if an I/O error occurs in the specified stream.
- NullPointerException- if- out == null.
 
- 
CBZip2OutputStreamConstructs a newCBZip2OutputStreamwith specified blocksize.Attention: The caller is responsible to write the two BZip2 magic bytes "BZ"to the specified stream prior to calling this constructor.- Parameters:
- out- the destination stream.
- blockSize- the blockSize as 100k units.
- Throws:
- IOException- if an I/O error occurs in the specified stream.
- IllegalArgumentException- if- (blockSize < 1) || (blockSize > 9).
- NullPointerException- if- out == null.
- See Also:
 
 
- 
- 
Method Details- 
hbMakeCodeLengthsprotected 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.- Parameters:
- len- char[]
- freq- char[]
- alphaSize- int
- maxLen- int
 
- 
chooseBlockSizepublic static int chooseBlockSize(long inputLength) Chooses a blocksize based on the given length of the data to compress.- Parameters:
- inputLength- The length of the data which will be compressed by- CBZip2OutputStream.
- Returns:
- The blocksize, between MIN_BLOCKSIZEandMAX_BLOCKSIZEboth inclusive. For a negativeinputLengththis method returnsMAX_BLOCKSIZEalways.
 
- 
write- Specified by:
- writein class- OutputStream
- Throws:
- IOException
 
- 
finalize
- 
finish- Throws:
- IOException
 
- 
close- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- OutputStream
- Throws:
- IOException
 
- 
flush- Specified by:
- flushin interface- Flushable
- Overrides:
- flushin class- OutputStream
- Throws:
- IOException
 
- 
getBlockSizepublic final int getBlockSize()Returns the blocksize parameter specified at construction time.- Returns:
- int
 
- 
write- Overrides:
- writein class- OutputStream
- Throws:
- IOException
 
 
-