Class 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.
    • 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 - if in == 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 created
        decompressConcatenated - 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 Detail

      • 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
      • 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 check
        length - 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 split
        endOffset - 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