Module datarush.commons
Class BZip2CompressorInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.compress.compressors.CompressorInputStream
-
- com.pervasive.datarush.io.compression.bzip2.BZip2CompressorInputStream
-
- All Implemented Interfaces:
BZip2Constants
,Closeable
,AutoCloseable
public class BZip2CompressorInputStream extends org.apache.commons.compress.compressors.CompressorInputStream implements BZip2Constants
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 static class
BZip2CompressorInputStream.ReadMode
-
Field Summary
-
Fields inherited from interface com.pervasive.datarush.io.compression.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(InputStream in)
Constructs a new BZip2CompressorInputStream which decompresses bytes read from the specified stream.BZip2CompressorInputStream(InputStream in, BZip2CompressorInputStream.ReadMode readMode)
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 void
close()
long
getPosition()
Get the current byte position with the raw input data stream.boolean
initBlock()
Initialize the next compression block.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)
boolean
skipToBlock(long startOffset, long endOffset)
Skip from the current raw input stream position to the start of the split boundary defined by the given start offset and end offset.-
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
-
-
-
-
Constructor Detail
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(InputStream in) throws IOException
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
- ifin == null
-
BZip2CompressorInputStream
public BZip2CompressorInputStream(InputStream in, BZip2CompressorInputStream.ReadMode readMode) 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
- ifin == null
-
-
Method Detail
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] dest, int offs, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
initBlock
public boolean initBlock() throws IOException
Initialize the next compression block. If at end of stream (the EOS marker) then determine if a concatenated bzip2 stream follows.- Returns:
- true if at beginning of next block; false if EOS encountered
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- 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
-
skipToBlock
public boolean skipToBlock(long startOffset, long endOffset) throws IOException
Skip from the current raw input stream position to the start of the split boundary defined by the given start offset and end offset. Once positioned at the start of the split, search for the magic marker that indicates the start of a compression block. Once found, cache the data read from the raw input stream into a byte buffer for processing.- Parameters:
startOffset
- start byte offset of the data splitendOffset
- end byte offset of the data split- Throws:
IOException
- thrown if any I/O errors occur
-
getPosition
public long getPosition()
Get the current byte position with the raw input data stream. This position can be used to determine if the raw stream has crossed a split boundary or not.- Returns:
- byte position with the raw data stream
-
-