Class BZip2CompressorInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.compress.compressors.CompressorInputStream
org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
- All Implemented Interfaces:
Closeable
,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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BitInputStream
private boolean
private int
always: in the range 0 ..private int
private int
private final CRC
private int
private BZip2CompressorInputStream.Data
All memory intensive stuff.private final boolean
private static final int
private int
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
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
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
ConstructorsConstructorDescriptionConstructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream.BZip2CompressorInputStream
(InputStream in, boolean decompressConcatenated) Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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, String name) void
close()
private boolean
complete()
private void
createHuffmanDecodingTables
(int alphaSize, int nGroups) Called by recvDecodingTables() exclusively.private void
endBlock()
private void
private int
long
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
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
private void
private int
private int
private int
private int
private int
private int
private int
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, read, readAllBytes, 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 Details
-
last
private int lastIndex of the last char in the block, so the block size == last + 1. -
origPtr
private int origPtrIndex in zptr[] of original string after sorting. -
blockSize100k
private int blockSize100kalways: in the range 0 .. 9. The current block size is 100000 * this number. -
blockRandomised
private boolean blockRandomised -
crc
-
nInUse
private int nInUse -
bin
-
decompressConcatenated
private final boolean decompressConcatenated -
EOF
private static final int EOF- See Also:
-
START_BLOCK_STATE
private static final int START_BLOCK_STATE- See Also:
-
RAND_PART_A_STATE
private static final int RAND_PART_A_STATE- See Also:
-
RAND_PART_B_STATE
private static final int RAND_PART_B_STATE- See Also:
-
RAND_PART_C_STATE
private static final int RAND_PART_C_STATE- See Also:
-
NO_RAND_PART_A_STATE
private static final int NO_RAND_PART_A_STATE- See Also:
-
NO_RAND_PART_B_STATE
private static final int NO_RAND_PART_B_STATE- See Also:
-
NO_RAND_PART_C_STATE
private static final int NO_RAND_PART_C_STATE- See Also:
-
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
All memory intensive stuff. This field is initialized by initBlock().
-
-
Constructor Details
-
BZip2CompressorInputStream
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream. This doesn't support decompressing concatenated .bz2 files.- Parameters:
in
- the InputStream from which this object should be created- Throws:
IOException
- if the stream content is malformed or an I/O error occurs.NullPointerException
- ifin == null
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(InputStream in, boolean decompressConcatenated) throws 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:
IOException
- ifin == null
, the stream content is malformed, or an I/O error occurs.
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
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
- Throws:
IOException
-
readNextByte
- Throws:
IOException
-
init
- Throws:
IOException
-
initBlock
- Throws:
IOException
-
endBlock
- Throws:
IOException
-
complete
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
bsR
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:
IOException
-
bsGetBit
- Throws:
IOException
-
bsGetUByte
- Throws:
IOException
-
bsGetInt
- Throws:
IOException
-
checkBounds
- Throws:
IOException
-
hbCreateDecodeTables
private static void hbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, int alphaSize) throws IOException Called by createHuffmanDecodingTables() exclusively.- Throws:
IOException
-
recvDecodingTables
- Throws:
IOException
-
createHuffmanDecodingTables
Called by recvDecodingTables() exclusively.- Throws:
IOException
-
getAndMoveToFrontDecode
- Throws:
IOException
-
getAndMoveToFrontDecode0
- Throws:
IOException
-
setupBlock
- Throws:
IOException
-
setupRandPartA
- Throws:
IOException
-
setupNoRandPartA
- Throws:
IOException
-
setupRandPartB
- Throws:
IOException
-
setupRandPartC
- Throws:
IOException
-
setupNoRandPartB
- Throws:
IOException
-
setupNoRandPartC
- Throws:
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
-