org.archive.io
Class GzipHeader

java.lang.Object
  extended by org.archive.io.GzipHeader

public class GzipHeader
extends java.lang.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 Summary
protected  int flg
          The GZIP header FLG byte.
protected  int length
          Total length of the gzip header.
static int MINIMAL_GZIP_HEADER_LENGTH
          Length of minimal GZIP header.
 
Constructor Summary
GzipHeader()
          Shutdown constructor.
GzipHeader(java.io.InputStream in)
          Constructor.
 
Method Summary
 byte[] getFextra()
           
 int getFlg()
           
 int getLength()
           
 int getMtime()
           
 int getOs()
           
 int getXfl()
           
protected  int readByte(java.io.InputStream in)
          Read a byte.
protected  int readByte(java.io.InputStream in, java.util.zip.CRC32 crc)
          Read a byte.
protected  int readByte(java.io.InputStream in, java.util.zip.CRC32 crc, byte[] buffer, int offset, int length)
          Read a byte.
 void readHeader(java.io.InputStream in)
          Read in gzip header.
 boolean testGzipMagic(java.io.InputStream in)
          Test gzip magic is next in the stream.
 boolean testGzipMagic(java.io.InputStream in, java.util.zip.CRC32 crc)
          Test gzip magic is next in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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:
Constant Field Values

length

protected int length
Total length of the gzip header.


flg

protected int flg
The GZIP header FLG byte.

Constructor Detail

GzipHeader

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


GzipHeader

public GzipHeader(java.io.InputStream in)
           throws java.io.IOException
Constructor. This constructor advances the stream past any gzip header found.

Parameters:
in - InputStream to read from.
Throws:
java.io.IOException
Method Detail

readHeader

public void readHeader(java.io.InputStream in)
                throws java.io.IOException
Read in gzip header. Advances the stream past the gzip header.

Parameters:
in - InputStream.
Throws:
java.io.IOException - Throws if does not start with GZIP Header.

testGzipMagic

public boolean testGzipMagic(java.io.InputStream in)
                      throws java.io.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:
java.io.IOException

testGzipMagic

public boolean testGzipMagic(java.io.InputStream in,
                             java.util.zip.CRC32 crc)
                      throws java.io.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:
java.io.IOException

readByte

protected int readByte(java.io.InputStream in)
                throws java.io.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:
java.io.IOException

readByte

protected int readByte(java.io.InputStream in,
                       java.util.zip.CRC32 crc)
                throws java.io.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:
java.io.IOException

readByte

protected int readByte(java.io.InputStream in,
                       java.util.zip.CRC32 crc,
                       byte[] buffer,
                       int offset,
                       int length)
                throws java.io.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:
java.io.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.


Copyright © 2003-2011 Internet Archive. All Rights Reserved.