Class GzipHeader
java.lang.Object
org.archive.util.zip.GzipHeader
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
FieldsModifier and TypeFieldDescriptionprotected intThe GZIP header FLG byte.protected intTotal length of the gzip header.static final intLength of minimal GZIP header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]intgetFlg()intintgetMtime()intgetOs()intgetXfl()protected intreadByte(InputStream in) Read a byte.protected intreadByte(InputStream in, CRC32 crc) Read a byte.protected intreadByte(InputStream in, CRC32 crc, byte[] buffer, int offset, int length) Read a byte.voidRead in gzip header.booleanTest gzip magic is next in the stream.booleantestGzipMagic(InputStream in, CRC32 crc) Test gzip magic is next in the stream.
-
Field Details
-
MINIMAL_GZIP_HEADER_LENGTH
public static final int MINIMAL_GZIP_HEADER_LENGTHLength of minimal GZIP header. See RFC1952 for explaination of value of 10.- See Also:
-
length
protected int lengthTotal length of the gzip header. -
flg
protected int flgThe GZIP header FLG byte.
-
-
Constructor Details
-
GzipHeader
public GzipHeader()Shutdown constructor. Must pass an input stream. -
GzipHeader
Constructor. This constructor advances the stream past any gzip header found.- Parameters:
in- InputStream to read from.- Throws:
IOException
-
-
Method Details
-
readHeader
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
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
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
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
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.
-