Class BZip2CompressorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.jboss.shrinkwrap.impl.base.io.tar.bzip.BZip2CompressorInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,BZip2Constants
public class BZip2CompressorInputStream extends java.io.InputStream implements 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 Modifier and Type Class Description private static classBZip2CompressorInputStream.Data
-
Field Summary
Fields Modifier and Type Field Description private booleanblockRandomisedprivate intblockSize100kalways: in the range 0 ..private intbsBuffprivate intbsLiveprivate longbytesReadprivate intcomputedBlockCRCprivate intcomputedCombinedCRCprivate CRCcrcprivate intcurrentCharprivate intcurrentStateprivate BZip2CompressorInputStream.DatadataAll memory intensive stuff.private booleandecompressConcatenatedprivate static intEOFprivate java.io.InputStreaminprivate intlastIndex of the last char in the block, so the block size == last + 1.private intnInUseprivate static intNO_RAND_PART_A_STATEprivate static intNO_RAND_PART_B_STATEprivate static intNO_RAND_PART_C_STATEprivate intorigPtrIndex in zptr[] of original string after sorting.private static intRAND_PART_A_STATEprivate static intRAND_PART_B_STATEprivate static intRAND_PART_C_STATEprivate static intSTART_BLOCK_STATEprivate intstoredBlockCRCprivate intstoredCombinedCRCprivate intsu_ch2private intsu_chPrevprivate intsu_countprivate intsu_i2private intsu_j2private intsu_rNToGoprivate intsu_rTPosprivate intsu_tPosprivate charsu_z-
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
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 Deprecated Methods Modifier and Type Method Description private booleanbsGetBit()private intbsGetInt()private charbsGetUByte()private intbsR(int n)voidclose()private booleancomplete()protected voidcount(int read)Increments the counter of already read bytes.protected voidcount(long read)Increments the counter of already read bytes.private voidcreateHuffmanDecodingTables(int alphaSize, int nGroups)Called by recvDecodingTables() exclusively.private voidendBlock()private voidgetAndMoveToFrontDecode()private intgetAndMoveToFrontDecode0(int groupNo)longgetBytesRead()Returns the current number of bytes read from this stream.intgetCount()Deprecated.this method may yield wrong results for large archives, use #getBytesRead insteadprivate static voidhbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, int alphaSize)Called by createHuffmanDecodingTables() exclusively.private booleaninit(boolean isFirstStream)private voidinitBlock()private voidmakeMaps()static booleanmatches(byte[] signature, int length)Checks if the signature matches what is expected for a bzip2 file.intread()intread(byte[] dest, int offs, int len)private intread0()private voidrecvDecodingTables()private voidsetupBlock()private voidsetupNoRandPartA()private voidsetupNoRandPartB()private voidsetupNoRandPartC()private voidsetupRandPartA()private voidsetupRandPartB()private voidsetupRandPartC()
-
-
-
Field Detail
-
bytesRead
private long bytesRead
-
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
-
bsBuff
private int bsBuff
-
bsLive
private int bsLive
-
crc
private final CRC crc
-
nInUse
private int nInUse
-
in
private java.io.InputStream in
-
decompressConcatenated
private final boolean decompressConcatenated
-
currentChar
private int currentChar
-
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.IOExceptionConstructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream. This doesn't suppprt decompressing concatenated .bz2 files.- Throws:
java.io.IOException- if the stream content is malformed or an I/O error occurs.java.lang.NullPointerException- if in == null
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(java.io.InputStream in, boolean decompressConcatenated) throws java.io.IOExceptionConstructs 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- if the stream content is malformed or an I/O error occurs.java.lang.NullPointerException- if in == null
-
-
Method Detail
-
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 public int 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
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] dest, int offs, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
makeMaps
private void makeMaps()
-
read0
private int read0() 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
bsR
private int bsR(int n) throws java.io.IOException- Throws:
java.io.IOException
-
bsGetBit
private boolean bsGetBit() throws java.io.IOException- Throws:
java.io.IOException
-
bsGetUByte
private char bsGetUByte() throws java.io.IOException- Throws:
java.io.IOException
-
bsGetInt
private int bsGetInt() 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)Called by createHuffmanDecodingTables() exclusively.
-
recvDecodingTables
private void recvDecodingTables() throws java.io.IOException- Throws:
java.io.IOException
-
createHuffmanDecodingTables
private void createHuffmanDecodingTables(int alphaSize, int nGroups)Called by recvDecodingTables() exclusively.
-
getAndMoveToFrontDecode
private void getAndMoveToFrontDecode() throws java.io.IOException- Throws:
java.io.IOException
-
getAndMoveToFrontDecode0
private int getAndMoveToFrontDecode0(int groupNo) throws java.io.IOException- Throws:
java.io.IOException
-
setupBlock
private void setupBlock() throws java.io.IOException- Throws:
java.io.IOException
-
setupRandPartA
private void setupRandPartA() throws java.io.IOException- Throws:
java.io.IOException
-
setupNoRandPartA
private void setupNoRandPartA() throws java.io.IOException- Throws:
java.io.IOException
-
setupRandPartB
private void setupRandPartB() throws java.io.IOException- Throws:
java.io.IOException
-
setupRandPartC
private void setupRandPartC() throws java.io.IOException- Throws:
java.io.IOException
-
setupNoRandPartB
private void setupNoRandPartB() throws java.io.IOException- Throws:
java.io.IOException
-
setupNoRandPartC
private void 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
-
-