Top Description Inners Fields Constructors Methods
org.apache.commons.compress.compressors.bzip2

public Class BZip2CompressorInputStream

extends CompressorInputStream
implements BZip2Constants, InputStreamStatistics
Class Inheritance
All Implemented Interfaces
org.apache.commons.compress.utils.InputStreamStatistics, org.apache.commons.compress.compressors.bzip2.BZip2Constants
Imports
java.io.IOException, .InputStream, java.nio.ByteOrder, java.util.Arrays, org.apache.commons.compress.compressors.CompressorInputStream, org.apache.commons.compress.utils.BitInputStream, .InputStreamStatistics, org.apache.commons.io.input.CloseShieldInputStream

An input stream that decompresses from the BZip2 format to be read as any other stream.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private BitInputStream
private boolean
private int
blockSize100k

always: in the range 0 ..

private int
private int
private final CRC
private int
private BZip2CompressorInputStream.Data
data

All memory intensive stuff.

private final boolean
private static final int
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
BZip2CompressorInputStream(final InputStream
the InputStream from which this object should be created
in
)

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

public
BZip2CompressorInputStream(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 BZip2CompressorInputStream which decompresses bytes read from the specified stream.

Method Summary

Modifier and TypeMethod and Description
private static boolean
private static int
private static char
private static int

Returns:

the requested bits combined into an int
bsR
(final BitInputStream bin, final int
the number of bits to read, must not exceed 32?
n
)

read bits from the input stream

private static void
checkBounds(final int checkVal, final int limitExclusive, final String name)

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
public long
getCompressedCount()

Implements org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Gets the amount of raw or compressed bytes read by the stream.
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(final boolean isFirstStream)

private void
private void
public static boolean

Returns:

true, if this stream is a bzip2 compressed stream, false otherwise
matches
(final byte[]
the bytes to check
signature
,
final int
the number of bytes to check
length
)

Checks if the signature matches what is expected for a bzip2 file.

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 int
private void
private int
private int
private int
private int
private int
private int
private int
Inherited from org.apache.commons.compress.compressors.CompressorInputStream:
countcountgetBytesReadgetCountgetUncompressedCountpushedBackBytes

Field Detail

binback to summary
private BitInputStream bin
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.

computedBlockCRCback to summary
private int computedBlockCRC
computedCombinedCRCback to summary
private int computedCombinedCRC
crcback to summary
private final CRC crc
currentStateback to summary
private int currentState
databack to summary
private BZip2CompressorInputStream.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
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

BZip2CompressorInputStreamback to summary
public BZip2CompressorInputStream(final InputStream in) throws IOException

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

Parameters
in:InputStream

the InputStream from which this object should be created

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

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

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 in == null, the stream content is malformed, or an I/O error occurs.

Method Detail

bsGetBitback to summary
private static boolean bsGetBit(final BitInputStream bin) throws IOException
bsGetIntback to summary
private static int bsGetInt(final BitInputStream bin) throws IOException
bsGetUByteback to summary
private static char bsGetUByte(final BitInputStream bin) throws IOException
bsRback to summary
private static int bsR(final BitInputStream bin, final int n) throws IOException

read bits from the input stream

Parameters
n:int

the number of bits to read, must not exceed 32?

Returns:int

the requested bits combined into an int

checkBoundsback to summary
private static void checkBounds(final int checkVal, final int limitExclusive, final String name) 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) throws IOException

Called by recvDecodingTables() exclusively.

endBlockback to summary
private void endBlock() throws IOException
getAndMoveToFrontDecodeback to summary
private void getAndMoveToFrontDecode() throws IOException
getAndMoveToFrontDecode0back to summary
private int getAndMoveToFrontDecode0() throws IOException
getCompressedCountback to summary
public long getCompressedCount()

Implements org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Doc from org.apache.commons.compress.utils.InputStreamStatistics.getCompressedCount.

Gets the amount of raw or compressed bytes read by the stream.

Returns:long

the amount of raw or compressed bytes read by the stream.

Annotations
@Override
Since
1.17
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) throws IOException

Called by createHuffmanDecodingTables() exclusively.

initback to summary
private boolean init(final boolean isFirstStream) throws IOException
initBlockback to summary
private void initBlock() throws IOException
makeMapsback to summary
private void makeMaps()
matchesback to summary
public static boolean matches(final byte[] signature, final int length)

Checks if the signature matches what is expected for a bzip2 file.

Parameters
signature:byte[]

the bytes to check

length:int

the number of bytes to check

Returns:boolean

true, if this stream is a bzip2 compressed stream, false otherwise

Since
1.1
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
readNextByteback to summary
private int readNextByte(final BitInputStream in) throws IOException
recvDecodingTablesback to summary
private void recvDecodingTables() throws IOException
setupBlockback to summary
private int setupBlock() throws IOException
setupNoRandPartAback to summary
private int setupNoRandPartA() throws IOException
setupNoRandPartBback to summary
private int setupNoRandPartB() throws IOException
setupNoRandPartCback to summary
private int setupNoRandPartC() throws IOException
setupRandPartAback to summary
private int setupRandPartA() throws IOException
setupRandPartBback to summary
private int setupRandPartB() throws IOException
setupRandPartCback to summary
private int setupRandPartC() throws IOException
org.apache.commons.compress.compressors.bzip2 back to summary

private final Class BZip2CompressorInputStream.Data

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.Data

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 final 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(final int blockSize100k)

Method Summary

Modifier and TypeMethod and Description
pack-priv int[]
initTT(final 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 final 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(final int blockSize100k)

Method Detail

initTTback to summary
pack-priv int[] initTT(final 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.