Class GZIPMemberSeries
java.lang.Object
java.io.InputStream
org.archive.format.gzip.GZIPMemberSeries
- All Implemented Interfaces:
Closeable,AutoCloseable,GZIPConstants
Class which encapsulates all the logic in reading multiple gzip members from
a single stream.
The class supports as it's main method, "nextMember()" which returns a
GZIPSeriesMember.
The class allows configuration as to the robustness, namely the handling of
errors in the underlying gzip stream.
Regardless of robustness - an IOException from the underlying Stream will
cause this class to throw an IOException whenever nextMember() is called.
In Strict mode, any GZ error within a member will cause the object to behave
as if an IOException was detected - nextMember() will repeatedly throw more
IOExceptions.
In Lax mode, a GZ error in a single member will cause this class to attempt
to skip that failing member, and find the next gzip member in the series.
This class maintains the state of the underlying gzip Stream:
) Deflating - a gzip header and some amount of deflate information has
been read, without errors
) IOError - an IOException has been detected on the underlying Stream
) Aligned - the gzip footer of a record has *just* been read, and it is
expected that the underlying Stream is either at EOF, or at the
start of another gzip member. In Strict Mode this is the
initial state.
) Scanning - The underlying Stream is in an unknown state - either because
of a GZ error in the previous member, and we're now attempting
to locate the next member. In Lax Mode, this is the initial
state.
The member returned by nextMember() is an InputStream, which also allows
access to information about the specific record, namely information in the
gzip header, as well as context information about the record within the
series: filename and offset. The Member also provides information about
the amount of compressed and uncompressed data read thus far.
If a gzip format exception is detected while in a read() call of the gzip
member, it will throw an IOException.GZIPFormatException to the caller.
when the end of the deflate stream is found in a read() call, the member
will also silently read the gzip footer, and check the length and CRC. A
failure to read the footer, or a bad comparison between length or CRC will
cause a GZIPFormatException to be thrown on that read() call.
if nextMember() is called and the previous member has not been completely
read, this class will automatically attempt to skip the previous record. If
an error is encountered, the class either either throw an exception, or
attempt to find the next member in the series.
- Author:
- brad
-
Field Summary
FieldsModifier and TypeFieldDescriptionintstatic intstatic intstatic intstatic intstatic intFields inherited from interface org.archive.format.gzip.GZIPConstants
BYTES_IN_INT, BYTES_IN_SHORT, GZIP_COMPRESSION_METHOD_DEFLATE, GZIP_COMPRESSION_METHOD_IDX, GZIP_FEXTRA_LENGTH_BYTES, GZIP_FEXTRA_LENGTH_IDX, GZIP_FEXTRA_NAME_BYTES, GZIP_FEXTRA_NAME_IDX, GZIP_FEXTRA_VALUE_IDX, GZIP_FEXTRA_VALUE_MAX_LENGTH, GZIP_FLAG_FCOMMENT, GZIP_FLAG_FEXTRA, GZIP_FLAG_FHCRC, GZIP_FLAG_FNAME, GZIP_FLAG_FTEXT, GZIP_FLAG_IDX, GZIP_FLAG_VALID_BITS, GZIP_FOOTER_BYTES, GZIP_MAGIC_ONE, GZIP_MAGIC_ONE_IDX, GZIP_MAGIC_TWO, GZIP_MAGIC_TWO_IDX, GZIP_MTIME_IDX, GZIP_MTIME_LENGTH, GZIP_OS_IDX, GZIP_OS_UNIX, GZIP_STATIC_FOOTER_SIZE, GZIP_STATIC_HEADER_SIZE, GZIP_XFL_IDX, LX_RECORD, LX_RECORD_VALUE, NO_BYTES_IN_STREAM, SL_RECORD -
Constructor Summary
ConstructorsConstructorDescriptionGZIPMemberSeries(Stream bis) GZIPMemberSeries(Stream bis, String context) GZIPMemberSeries(Stream bis, String context, long offset) GZIPMemberSeries(Stream bis, String context, long offset, boolean strict) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intfillInflater(Inflater inflater) longlongbooleangotEOF()booleanbooleanisStrict()voidvoidintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreturnBytes(int bytes) voidsetStrict(boolean strict) Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
-
Field Details
-
STATE_DEFLATING
public static int STATE_DEFLATING -
STATE_IOERROR
public static int STATE_IOERROR -
STATE_ALIGNED
public static int STATE_ALIGNED -
STATE_SCANNING
public static int STATE_SCANNING -
STATE_START
public static int STATE_START -
state
public int state
-
-
Constructor Details
-
GZIPMemberSeries
-
GZIPMemberSeries
-
GZIPMemberSeries
-
GZIPMemberSeries
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
gotEOF
public boolean gotEOF() -
gotIOError
public boolean gotIOError() -
getStreamContext
-
getCurrentMemberStartOffset
public long getCurrentMemberStartOffset() -
getOffset
public long getOffset() -
noteEndOfRecord
- Throws:
IOException
-
noteGZError
- Throws:
IOException
-
getNextMember
- Throws:
GZIPFormatExceptionIOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
returnBytes
public void returnBytes(int bytes) -
fillInflater
- Throws:
IOException
-
isStrict
public boolean isStrict()- Returns:
- the strict
-
setStrict
public void setStrict(boolean strict) - Parameters:
strict- the strict to set
-