Class BZip2CompressorInputStream
java.lang.Object
java.io.InputStream
org.jboss.shrinkwrap.impl.base.io.tar.bzip.BZip2CompressorInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BZip2Constants
An input stream that decompresses from the BZip2 format to be read as any other stream.
Forked from Apache Commons-Compress with possible changes
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private int
always: in the range 0 ..private int
private int
private long
private int
private int
private final CRC
private int
private int
private BZip2CompressorInputStream.Data
All memory intensive stuff.private final boolean
private static final int
private InputStream
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.jboss.shrinkwrap.impl.base.io.tar.bzip.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 boolean
bsGetBit()
private int
bsGetInt()
private char
private int
bsR
(int n) void
close()
private boolean
complete()
protected void
count
(int read) Increments the counter of already read bytes.protected void
count
(long read) Increments the counter of already read bytes.private void
createHuffmanDecodingTables
(int alphaSize, int nGroups) Called by recvDecodingTables() exclusively.private void
endBlock()
private void
private int
getAndMoveToFrontDecode0
(int groupNo) long
Returns the current number of bytes read from this stream.int
getCount()
Deprecated.this method may yield wrong results for large archives, use #getBytesRead insteadprivate 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 void
private void
private void
private void
private void
private void
private void
private void
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
-
Field Details
-
bytesRead
private long bytesRead -
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 -
bsBuff
private int bsBuff -
bsLive
private int bsLive -
crc
-
nInUse
private int nInUse -
in
-
decompressConcatenated
private final boolean decompressConcatenated -
currentChar
private int currentChar -
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 suppprt decompressing concatenated .bz2 files.- Throws:
IOException
- if the stream content is malformed or an I/O error occurs.NullPointerException
- if in == 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
- if the stream content is malformed or an I/O error occurs.NullPointerException
- if in == null
-
-
Method Details
-
count
protected void count(int read) Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)- Parameters:
read
- the number of bytes read- Since:
- 1.1
-
count
protected void count(long read) Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)- Parameters:
read
- the number of bytes read
-
getCount
Deprecated.this method may yield wrong results for large archives, use #getBytesRead insteadReturns the current number of bytes read from this stream.- Returns:
- the number of read bytes
-
getBytesRead
public long getBytesRead()Returns the current number of bytes read from this stream.- Returns:
- the number of read bytes
- Since:
- 1.1
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
makeMaps
private void makeMaps() -
read0
- 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
- Throws:
IOException
-
bsGetBit
- Throws:
IOException
-
bsGetUByte
- Throws:
IOException
-
bsGetInt
- Throws:
IOException
-
hbCreateDecodeTables
private static void hbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, int alphaSize) Called by createHuffmanDecodingTables() exclusively. -
recvDecodingTables
- Throws:
IOException
-
createHuffmanDecodingTables
private void createHuffmanDecodingTables(int alphaSize, int nGroups) Called by recvDecodingTables() exclusively. -
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
-