Class BZip2CompressorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.compress.compressors.CompressorInputStream
-
- org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,BZip2Constants
,InputStreamStatistics
public class BZip2CompressorInputStream extends CompressorInputStream implements BZip2Constants, InputStreamStatistics
An input stream that decompresses from the BZip2 format to be read as any other stream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BZip2CompressorInputStream.Data
-
Field Summary
Fields Modifier and Type Field Description private BitInputStream
bin
private boolean
blockRandomised
private int
blockSize100k
always: in the range 0 ..private int
computedBlockCRC
private int
computedCombinedCRC
private CRC
crc
private int
currentState
private BZip2CompressorInputStream.Data
data
All memory intensive stuff.private boolean
decompressConcatenated
private static int
EOF
private int
last
Index of the last char in the block, so the block size == last + 1.private int
nInUse
private static int
NO_RAND_PART_A_STATE
private static int
NO_RAND_PART_B_STATE
private static int
NO_RAND_PART_C_STATE
private int
origPtr
Index in zptr[] of original string after sorting.private static int
RAND_PART_A_STATE
private static int
RAND_PART_B_STATE
private static int
RAND_PART_C_STATE
private static int
START_BLOCK_STATE
private int
storedBlockCRC
private int
storedCombinedCRC
private int
su_ch2
private int
su_chPrev
private int
su_count
private int
su_i2
private int
su_j2
private int
su_rNToGo
private int
su_rTPos
private int
su_tPos
private char
su_z
-
Fields inherited from interface org.apache.commons.compress.compressors.bzip2.BZip2Constants
BASEBLOCKSIZE, G_SIZE, MAX_ALPHA_SIZE, MAX_CODE_LEN, MAX_SELECTORS, N_GROUPS, N_ITERS, NUM_OVERSHOOT_BYTES, RUNA, RUNB
-
-
Constructor Summary
Constructors Constructor Description BZip2CompressorInputStream(java.io.InputStream in)
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream.BZip2CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated)
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static boolean
bsGetBit(BitInputStream bin)
private static int
bsGetInt(BitInputStream bin)
private static char
bsGetUByte(BitInputStream bin)
private static int
bsR(BitInputStream bin, int n)
read bits from the input streamprivate static void
checkBounds(int checkVal, int limitExclusive, java.lang.String name)
void
close()
private boolean
complete()
private void
createHuffmanDecodingTables(int alphaSize, int nGroups)
Called by recvDecodingTables() exclusively.private void
endBlock()
private void
getAndMoveToFrontDecode()
private int
getAndMoveToFrontDecode0()
long
getCompressedCount()
private static void
hbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, int alphaSize)
Called by createHuffmanDecodingTables() exclusively.private boolean
init(boolean isFirstStream)
private void
initBlock()
private void
makeMaps()
static boolean
matches(byte[] signature, int length)
Checks if the signature matches what is expected for a bzip2 file.int
read()
int
read(byte[] dest, int offs, int len)
private int
read0()
private int
readNextByte(BitInputStream in)
private void
recvDecodingTables()
private int
setupBlock()
private int
setupNoRandPartA()
private int
setupNoRandPartB()
private int
setupNoRandPartC()
private int
setupRandPartA()
private int
setupRandPartB()
private int
setupRandPartC()
-
Methods inherited from class org.apache.commons.compress.compressors.CompressorInputStream
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytes
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.compress.utils.InputStreamStatistics
getUncompressedCount
-
-
-
-
Field Detail
-
last
private int last
Index of the last char in the block, so the block size == last + 1.
-
origPtr
private int origPtr
Index in zptr[] of original string after sorting.
-
blockSize100k
private int blockSize100k
always: in the range 0 .. 9. The current block size is 100000 * this number.
-
blockRandomised
private boolean blockRandomised
-
crc
private final CRC crc
-
nInUse
private int nInUse
-
bin
private BitInputStream bin
-
decompressConcatenated
private final boolean decompressConcatenated
-
EOF
private static final int EOF
- See Also:
- Constant Field Values
-
START_BLOCK_STATE
private static final int START_BLOCK_STATE
- See Also:
- Constant Field Values
-
RAND_PART_A_STATE
private static final int RAND_PART_A_STATE
- See Also:
- Constant Field Values
-
RAND_PART_B_STATE
private static final int RAND_PART_B_STATE
- See Also:
- Constant Field Values
-
RAND_PART_C_STATE
private static final int RAND_PART_C_STATE
- See Also:
- Constant Field Values
-
NO_RAND_PART_A_STATE
private static final int NO_RAND_PART_A_STATE
- See Also:
- Constant Field Values
-
NO_RAND_PART_B_STATE
private static final int NO_RAND_PART_B_STATE
- See Also:
- Constant Field Values
-
NO_RAND_PART_C_STATE
private static final int NO_RAND_PART_C_STATE
- See Also:
- Constant Field Values
-
currentState
private int currentState
-
storedBlockCRC
private int storedBlockCRC
-
storedCombinedCRC
private int storedCombinedCRC
-
computedBlockCRC
private int computedBlockCRC
-
computedCombinedCRC
private int computedCombinedCRC
-
su_count
private int su_count
-
su_ch2
private int su_ch2
-
su_chPrev
private int su_chPrev
-
su_i2
private int su_i2
-
su_j2
private int su_j2
-
su_rNToGo
private int su_rNToGo
-
su_rTPos
private int su_rTPos
-
su_tPos
private int su_tPos
-
su_z
private char su_z
-
data
private BZip2CompressorInputStream.Data data
All memory intensive stuff. This field is initialized by initBlock().
-
-
Constructor Detail
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(java.io.InputStream in) throws java.io.IOException
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream. This doesn't suppprt decompressing concatenated .bz2 files.- Parameters:
in
- the InputStream from which this object should be created- Throws:
java.io.IOException
- if the stream content is malformed or an I/O error occurs.java.lang.NullPointerException
- ifin == null
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated) throws java.io.IOException
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream.- Parameters:
in
- the InputStream from which this object should be createddecompressConcatenated
- 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- Throws:
java.io.IOException
- ifin == null
, the stream content is malformed, or an I/O error occurs.
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] dest, int offs, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
getCompressedCount
public long getCompressedCount()
- Specified by:
getCompressedCount
in interfaceInputStreamStatistics
- Returns:
- the amount of raw or compressed bytes read by the stream
- Since:
- 1.17
-
makeMaps
private void makeMaps()
-
read0
private int read0() throws java.io.IOException
- Throws:
java.io.IOException
-
readNextByte
private int readNextByte(BitInputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
init
private boolean init(boolean isFirstStream) throws java.io.IOException
- Throws:
java.io.IOException
-
initBlock
private void initBlock() throws java.io.IOException
- Throws:
java.io.IOException
-
endBlock
private void endBlock() throws java.io.IOException
- Throws:
java.io.IOException
-
complete
private boolean complete() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
bsR
private static int bsR(BitInputStream bin, int n) throws java.io.IOException
read bits from the input stream- Parameters:
n
- the number of bits to read, must not exceed 32?- Returns:
- the requested bits combined into an int
- Throws:
java.io.IOException
-
bsGetBit
private static boolean bsGetBit(BitInputStream bin) throws java.io.IOException
- Throws:
java.io.IOException
-
bsGetUByte
private static char bsGetUByte(BitInputStream bin) throws java.io.IOException
- Throws:
java.io.IOException
-
bsGetInt
private static int bsGetInt(BitInputStream bin) throws java.io.IOException
- Throws:
java.io.IOException
-
checkBounds
private static void checkBounds(int checkVal, int limitExclusive, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
hbCreateDecodeTables
private static void hbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, int alphaSize) throws java.io.IOException
Called by createHuffmanDecodingTables() exclusively.- Throws:
java.io.IOException
-
recvDecodingTables
private void recvDecodingTables() throws java.io.IOException
- Throws:
java.io.IOException
-
createHuffmanDecodingTables
private void createHuffmanDecodingTables(int alphaSize, int nGroups) throws java.io.IOException
Called by recvDecodingTables() exclusively.- Throws:
java.io.IOException
-
getAndMoveToFrontDecode
private void getAndMoveToFrontDecode() throws java.io.IOException
- Throws:
java.io.IOException
-
getAndMoveToFrontDecode0
private int getAndMoveToFrontDecode0() throws java.io.IOException
- Throws:
java.io.IOException
-
setupBlock
private int setupBlock() throws java.io.IOException
- Throws:
java.io.IOException
-
setupRandPartA
private int setupRandPartA() throws java.io.IOException
- Throws:
java.io.IOException
-
setupNoRandPartA
private int setupNoRandPartA() throws java.io.IOException
- Throws:
java.io.IOException
-
setupRandPartB
private int setupRandPartB() throws java.io.IOException
- Throws:
java.io.IOException
-
setupRandPartC
private int setupRandPartC() throws java.io.IOException
- Throws:
java.io.IOException
-
setupNoRandPartB
private int setupNoRandPartB() throws java.io.IOException
- Throws:
java.io.IOException
-
setupNoRandPartC
private int setupNoRandPartC() throws java.io.IOException
- Throws:
java.io.IOException
-
matches
public static boolean matches(byte[] signature, int length)
Checks if the signature matches what is expected for a bzip2 file.- Parameters:
signature
- the bytes to checklength
- the number of bytes to check- Returns:
- true, if this stream is a bzip2 compressed stream, false otherwise
- Since:
- 1.1
-
-