Class GzipCompressorInputStream

java.lang.Object
java.io.InputStream
org.apache.commons.compress.compressors.CompressorInputStream
org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, InputStreamStatistics

Input stream that decompresses .gz files.

This supports decompressing concatenated .gz files which is important when decompressing standalone .gz files.

Instead of using java.util.zip.GZIPInputStream, this class has its own GZIP member decoder. The actual decompression is done with Inflater.

If you use the constructor GzipCompressorInputStream(in) or GzipCompressorInputStream(in, false), then read() will return -1 as soon as the first encoded GZIP member has been completely read. In this case, if the underlying input stream supports mark() and reset(), then it will be left positioned just after the end of the encoded GZIP member; otherwise, some indeterminate number of extra bytes following the encoded GZIP member will have been consumed and discarded.

If you use the constructor GzipCompressorInputStream(in, true) then read() will return -1 only after the entire input stream has been exhausted; any bytes that follow an encoded GZIP member must constitute a new encoded GZIP member, otherwise an IOException is thrown. The data read from a stream constructed this way will consist of the concatenated data of all of the encoded GZIP members in order.

See Also:
  • "https://tools.ietf.org/html/rfc1952"
  • Constructor Details

    • GzipCompressorInputStream

      Constructs a new input stream that decompresses gzip-compressed data from the specified input stream.

      This is equivalent to GzipCompressorInputStream(inputStream, false) and thus will not decompress concatenated .gz files.

      Parameters:
      inputStream - the InputStream from which this object should be created of
      Throws:
      IOException - if the stream could not be created
    • GzipCompressorInputStream

      public GzipCompressorInputStream(InputStream inputStream, boolean decompressConcatenated) throws IOException
      Constructs a new input stream that decompresses gzip-compressed data from the specified input stream.

      If decompressConcatenated is false: This decompressor might read more input than it will actually use. If inputStream supports mark and reset, then the input position will be adjusted so that it is right after the last byte of the compressed stream. If mark isn't supported, the input position will be undefined.

      Parameters:
      inputStream - the InputStream from which this object should be created of
      decompressConcatenated - if true, decompress until the end of the input; if false, stop after the first .gz member
      Throws:
      IOException - if the stream could not be created
  • Method Details