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.

GZIPInputStream doesn't decompress concatenated .gz files: it stops after the first member and silently ignores the rest. It doesn't leave the read position to point to the beginning of the next member, which makes it difficult workaround the lack of concatenation support.

Instead of using GZIPInputStream, this class has its own .gz container format decoder. The actual decompression is done with Inflater.

If you use the constructor GzipCompressorInputStream(in) or GzipCompressorInputStream(in, false) with some InputStream in then read() will return -1 as soon as the first internal member has been read completely. The stream in will be positioned at the start of the second gzip member if there is one.

If you use the constructor GzipCompressorInputStream(in, true) with some InputStream in then read() will return -1 once the stream in has been exhausted. The data read from a stream constructed this way will consist of the concatenated data of all gzip members contained inside in.

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