Class GZIPInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class GZIPInputStream extends InflaterInputStream
This filter stream is used to decompress a "GZIP" format stream. The "GZIP" format is described in RFC 1952.
Since:
JDK 1.1
  • Field Details

    • GZIP_MAGIC

      public static final int GZIP_MAGIC
      The magic number found at the start of a GZIP stream.
      See Also:
    • FTEXT

      static final int FTEXT
      The mask for bit 0 of the flag byte.
      See Also:
    • FHCRC

      static final int FHCRC
      The mask for bit 1 of the flag byte.
      See Also:
    • FEXTRA

      static final int FEXTRA
      The mask for bit 2 of the flag byte.
      See Also:
    • FNAME

      static final int FNAME
      The mask for bit 3 of the flag byte.
      See Also:
    • FCOMMENT

      static final int FCOMMENT
      The mask for bit 4 of the flag byte.
      See Also:
    • crc

      protected CRC32 crc
      The CRC-32 checksum value for uncompressed data.
    • eos

      protected boolean eos
      Indicates whether or not the end of the stream has been reached.
    • readGZIPHeader

      private boolean readGZIPHeader
      Indicates whether or not the GZIP header has been read in.
  • Constructor Details

    • GZIPInputStream

      public GZIPInputStream(InputStream in) throws IOException
      Creates a GZIPInputStream with the default buffer size.
      Parameters:
      in - The stream to read compressed data from (in GZIP format).
      Throws:
      IOException - if an error occurs during an I/O operation.
    • GZIPInputStream

      public GZIPInputStream(InputStream in, int size) throws IOException
      Creates a GZIPInputStream with the specified buffer size.
      Parameters:
      in - The stream to read compressed data from (in GZIP format).
      size - The size of the buffer to use.
      Throws:
      IOException - if an error occurs during an I/O operation.
      IllegalArgumentException - if size is less than or equal to 0.
  • Method Details

    • close

      public void close() throws IOException
      Closes the input stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InflaterInputStream
      Throws:
      IOException - if an error occurs during an I/O operation.
    • read

      public int read(byte[] buf, int offset, int len) throws IOException
      Reads in GZIP-compressed data and stores it in uncompressed form into an array of bytes. The method will block until either enough input data becomes available or the compressed stream reaches its end.
      Overrides:
      read in class InflaterInputStream
      Parameters:
      buf - the buffer into which the uncompressed data will be stored.
      offset - the offset indicating where in buf the uncompressed data should be placed.
      len - the number of uncompressed bytes to be read.
      Throws:
      IOException
    • readHeader

      private void readHeader() throws IOException
      Reads in the GZIP header.
      Throws:
      IOException
    • readFooter

      private void readFooter() throws IOException
      Throws:
      IOException