Class GzipHeader

java.lang.Object
org.archive.util.zip.GzipHeader

public class GzipHeader extends Object
Read in the GZIP header. See RFC1952 for specification on what the header looks like. Assumption is that stream is cued-up with the gzip header as the next thing to be read.

Of Java and unsigned bytes. That is, its always a signed int in java no matter what the qualifier whether byte, char, etc.

Add accessors for optional filename, comment and MTIME.

Author:
stack
  • Field Details

    • MINIMAL_GZIP_HEADER_LENGTH

      public static final int MINIMAL_GZIP_HEADER_LENGTH
      Length of minimal GZIP header. See RFC1952 for explaination of value of 10.
      See Also:
    • length

      protected int length
      Total length of the gzip header.
    • flg

      protected int flg
      The GZIP header FLG byte.
  • Constructor Details

    • GzipHeader

      public GzipHeader()
      Shutdown constructor. Must pass an input stream.
    • GzipHeader

      public GzipHeader(InputStream in) throws IOException
      Constructor. This constructor advances the stream past any gzip header found.
      Parameters:
      in - InputStream to read from.
      Throws:
      IOException
  • Method Details

    • readHeader

      public void readHeader(InputStream in) throws IOException
      Read in gzip header. Advances the stream past the gzip header.
      Parameters:
      in - InputStream.
      Throws:
      IOException - Throws if does not start with GZIP Header.
    • testGzipMagic

      public boolean testGzipMagic(InputStream in) throws IOException
      Test gzip magic is next in the stream. Reads two bytes. Caller needs to manage resetting stream.
      Parameters:
      in - InputStream to read.
      Returns:
      true if found gzip magic. False otherwise or an IOException (including EOFException).
      Throws:
      IOException
    • testGzipMagic

      public boolean testGzipMagic(InputStream in, CRC32 crc) throws IOException
      Test gzip magic is next in the stream. Reads two bytes. Caller needs to manage resetting stream.
      Parameters:
      in - InputStream to read.
      crc - CRC to update.
      Returns:
      true if found gzip magic. False otherwise or an IOException (including EOFException).
      Throws:
      IOException
    • readByte

      protected int readByte(InputStream in) throws IOException
      Read a byte. We do not expect to get a -1 reading. If we do, we throw exception. Update the crc as we go.
      Parameters:
      in - InputStream to read.
      Returns:
      Byte read.
      Throws:
      IOException
    • readByte

      protected int readByte(InputStream in, CRC32 crc) throws IOException
      Read a byte. We do not expect to get a -1 reading. If we do, we throw exception. Update the crc as we go.
      Parameters:
      in - InputStream to read.
      crc - CRC to update.
      Returns:
      Byte read.
      Throws:
      IOException
    • readByte

      protected int readByte(InputStream in, CRC32 crc, byte[] buffer, int offset, int length) throws IOException
      Read a byte. We do not expect to get a -1 reading. If we do, we throw exception. Update the crc as we go.
      Parameters:
      in - InputStream to read.
      crc - CRC to update.
      buffer - Buffer to read into.
      offset - Offset to start filling buffer at.
      length - How much to read.
      Returns:
      Bytes read.
      Throws:
      IOException
    • getFextra

      public byte[] getFextra()
      Returns:
      Returns the fextra.
    • getFlg

      public int getFlg()
      Returns:
      Returns the flg.
    • getOs

      public int getOs()
      Returns:
      Returns the os.
    • getXfl

      public int getXfl()
      Returns:
      Returns the xfl.
    • getMtime

      public int getMtime()
      Returns:
      Returns the mtime.
    • getLength

      public int getLength()
      Returns:
      Returns the length.