Top Description Inners Fields Constructors Methods
org.apache.tools.bzip2

public Class CBZip2InputStream

extends InputStream
implements BZip2Constants
Class Inheritance
All Implemented Interfaces
org.apache.tools.bzip2.BZip2Constants
Imports
java.io.IOException, .InputStream

An input stream that decompresses from the BZip2 format (without the file header chars) to be read as any other stream.

The decompression requires large amounts of memory. Thus you should call the close() method as soon as possible, to force CBZip2InputStream to release the allocated memory. See CBZip2OutputStream for information about memory usage.

CBZip2InputStream reads bytes from the compressed source stream via the single byte read() method exclusively. Thus you should consider to use a buffered source stream.

Instances of this class are not threadsafe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private int
blockSize100k

always: in the range 0 ..

private int
private int
private int
private int
private final CRC
private int
private int
private CBZip2InputStream.Data
data

All memory intensive stuff.

private final boolean
private static final int
private InputStream
private int
last

Index of the last char in the block, so the block size == last + 1.

private int
private static final int
private static final int
private static final int
private int
origPtr

Index in zptr[] of original string after sorting.

private static final int
private static final int
private static final int
private static final int
private int
private int
private int
private int
private int
private int
private int
private int
private int
private int
private char

Constructor Summary

AccessConstructor and Description
public
CBZip2InputStream(final InputStream
InputStream
in
)

Constructs a new CBZip2InputStream which decompresses bytes read from the specified stream.

public
CBZip2InputStream(final InputStream
the InputStream from which this object should be created
in
,
final boolean
if true, decompress until the end of the input; if false, stop after the first .bz2 stream and leave the input position to point to the next byte after the .bz2 stream
decompressConcatenated
)

Constructs a new CBZip2InputStream which decompresses bytes read from the specified stream.

Method Summary

Modifier and TypeMethod and Description
private boolean
private int
private char
private int
bsR(final int n)

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
private boolean
private void
createHuffmanDecodingTables(final int alphaSize, final int nGroups)

Called by recvDecodingTables() exclusively.

private void
private void
private int
getAndMoveToFrontDecode0(final int groupNo)

private static void
hbCreateDecodeTables(final int[] limit, final int[] base, final int[] perm, final char[] length, final int minLen, final int maxLen, final int alphaSize)

Called by createHuffmanDecodingTables() exclusively.

private boolean
init(boolean isFirstStream)

private void
private void
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.
public int
read(final byte[]
the buffer into which the data is read.
dest
,
final int
the start offset in array b at which the data is written.
offs
,
final int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.
private int
private void
private static void
private void
private void
private void
private void
private void
private void
private void
Inherited from java.io.InputStream:
availablemarkmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

blockRandomisedback to summary
private boolean blockRandomised
blockSize100kback to summary
private int blockSize100k

always: in the range 0 .. 9. The current block size is 100000 * this number.

bsBuffback to summary
private int bsBuff
bsLiveback to summary
private int bsLive
computedBlockCRCback to summary
private int computedBlockCRC
computedCombinedCRCback to summary
private int computedCombinedCRC
crcback to summary
private final CRC crc
currentCharback to summary
private int currentChar
currentStateback to summary
private int currentState
databack to summary
private CBZip2InputStream.Data data

All memory intensive stuff. This field is initialized by initBlock().

decompressConcatenatedback to summary
private final boolean decompressConcatenated
EOFback to summary
private static final int EOF
inback to summary
private InputStream in
lastback to summary
private int last

Index of the last char in the block, so the block size == last + 1.

nInUseback to summary
private int nInUse
NO_RAND_PART_A_STATEback to summary
private static final int NO_RAND_PART_A_STATE
NO_RAND_PART_B_STATEback to summary
private static final int NO_RAND_PART_B_STATE
NO_RAND_PART_C_STATEback to summary
private static final int NO_RAND_PART_C_STATE
origPtrback to summary
private int origPtr

Index in zptr[] of original string after sorting.

RAND_PART_A_STATEback to summary
private static final int RAND_PART_A_STATE
RAND_PART_B_STATEback to summary
private static final int RAND_PART_B_STATE
RAND_PART_C_STATEback to summary
private static final int RAND_PART_C_STATE
START_BLOCK_STATEback to summary
private static final int START_BLOCK_STATE
storedBlockCRCback to summary
private int storedBlockCRC
storedCombinedCRCback to summary
private int storedCombinedCRC
su_ch2back to summary
private int su_ch2
su_chPrevback to summary
private int su_chPrev
su_countback to summary
private int su_count
su_i2back to summary
private int su_i2
su_j2back to summary
private int su_j2
su_rNToGoback to summary
private int su_rNToGo
su_rTPosback to summary
private int su_rTPos
su_tPosback to summary
private int su_tPos
su_zback to summary
private char su_z

Constructor Detail

CBZip2InputStreamback to summary
public CBZip2InputStream(final InputStream in) throws IOException

Constructs a new CBZip2InputStream which decompresses bytes read from the specified stream. This doesn't support decompressing concatenated .bz2 files.

Although BZip2 headers are marked with the magic "Bz" this constructor expects the next byte in the stream to be the first one after the magic. Thus callers have to skip the first two bytes. Otherwise this constructor will throw an exception.

Parameters
in:InputStream

InputStream

Exceptions
IOException:
if the stream content is malformed or an I/O error occurs.
NullPointerException:
if in == null
CBZip2InputStreamback to summary
public CBZip2InputStream(final InputStream in, final boolean decompressConcatenated) throws IOException

Constructs a new CBZip2InputStream which decompresses bytes read from the specified stream.

Although BZip2 headers are marked with the magic "Bz" this constructor expects the next byte in the stream to be the first one after the magic. Thus callers have to skip the first two bytes. Otherwise this constructor will throw an exception.

Parameters
in:InputStream

the InputStream from which this object should be created

decompressConcatenated:boolean

if true, decompress until the end of the input; if false, stop after the first .bz2 stream and leave the input position to point to the next byte after the .bz2 stream

Exceptions
IOException:
if the stream content is malformed or an I/O error occurs.
NullPointerException:
if in == null

Method Detail

bsGetBitback to summary
private boolean bsGetBit() throws IOException
bsGetIntback to summary
private int bsGetInt() throws IOException
bsGetUByteback to summary
private char bsGetUByte() throws IOException
bsRback to summary
private int bsR(final int n) throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
completeback to summary
private boolean complete() throws IOException
createHuffmanDecodingTablesback to summary
private void createHuffmanDecodingTables(final int alphaSize, final int nGroups)

Called by recvDecodingTables() exclusively.

endBlockback to summary
private void endBlock()
getAndMoveToFrontDecodeback to summary
private void getAndMoveToFrontDecode() throws IOException
getAndMoveToFrontDecode0back to summary
private int getAndMoveToFrontDecode0(final int groupNo) throws IOException
hbCreateDecodeTablesback to summary
private static void hbCreateDecodeTables(final int[] limit, final int[] base, final int[] perm, final char[] length, final int minLen, final int maxLen, final int alphaSize)

Called by createHuffmanDecodingTables() exclusively.

initback to summary
private boolean init(boolean isFirstStream) throws IOException
initBlockback to summary
private void initBlock() throws IOException
makeMapsback to summary
private void makeMaps()
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(final byte[] dest, final int offs, final int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
dest:byte[]

the buffer into which the data is read.

offs:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
read0back to summary
private int read0() throws IOException
recvDecodingTablesback to summary
private void recvDecodingTables() throws IOException
reportCRCErrorback to summary
private static void reportCRCError()
setupBlockback to summary
private void setupBlock() throws IOException
setupNoRandPartAback to summary
private void setupNoRandPartA() throws IOException
setupNoRandPartBback to summary
private void setupNoRandPartB() throws IOException
setupNoRandPartCback to summary
private void setupNoRandPartC() throws IOException
setupRandPartAback to summary
private void setupRandPartA() throws IOException
setupRandPartBback to summary
private void setupRandPartB() throws IOException
setupRandPartCback to summary
private void setupRandPartC() throws IOException
org.apache.tools.bzip2 back to summary

private final Class CBZip2InputStream.Data

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int[][]
pack-priv final int[]
pack-priv final char[]
pack-priv final boolean[]
pack-priv final int[][]
pack-priv byte[]
pack-priv final int[]
pack-priv final int[][]
pack-priv final byte[]
pack-priv final byte[]
pack-priv final byte[]
pack-priv final byte[]
pack-priv final char[][]
pack-priv int[]
pack-priv final int[]
unzftab

Freq table collected to save a pass over the data during decompression.

Constructor Summary

AccessConstructor and Description
pack-priv
Data(int blockSize100k)

Method Summary

Modifier and TypeMethod and Description
pack-priv final int[]
initTT(int length)

Initializes the tt array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseback to summary
pack-priv final int[][] base
cftabback to summary
pack-priv final int[] cftab
getAndMoveToFrontDecode_yyback to summary
pack-priv final char[] getAndMoveToFrontDecode_yy
inUseback to summary
pack-priv final boolean[] inUse
limitback to summary
pack-priv final int[][] limit
ll8back to summary
pack-priv byte[] ll8
minLensback to summary
pack-priv final int[] minLens
permback to summary
pack-priv final int[][] perm
recvDecodingTables_posback to summary
pack-priv final byte[] recvDecodingTables_pos
selectorback to summary
pack-priv final byte[] selector
selectorMtfback to summary
pack-priv final byte[] selectorMtf
seqToUnseqback to summary
pack-priv final byte[] seqToUnseq
temp_charArray2dback to summary
pack-priv final char[][] temp_charArray2d
ttback to summary
pack-priv int[] tt
unzftabback to summary
pack-priv final int[] unzftab

Freq table collected to save a pass over the data during decompression.

Constructor Detail

Databack to summary
pack-priv Data(int blockSize100k)

Method Detail

initTTback to summary
pack-priv final int[] initTT(int length)

Initializes the tt array. This method is called when the required length of the array is known. I don't initialize it at construction time to avoid unnecessary memory allocation when compressing small files.