This supports decompressing concatenated .gz files which is important when decompressing standalone .gz files.
java. doesn't decompress concatenated .gz files: it stops after the first member and silently ignores the rest. It doesn't
leave the read position to point to the beginning of the next member, which makes it difficult workaround the lack of concatenation support.
Instead of using GZIPInputStream, this class has its own .gz container format decoder. The actual decompression is done with
java..
If you use the constructor GzipCompressorInputStream(in) or GzipCompressorInputStream(in, false) with some InputStream in then read will return -1 as soon as the first internal member has been read completely. The stream in will be
positioned at the start of the second gzip member if there is one.
If you use the constructor GzipCompressorInputStream(in,
true) with some InputStream in then read will return -1 once the stream in has been exhausted. The data read from a stream
constructed this way will consist of the concatenated data of all gzip members contained inside in.
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private int | |
| private final CountingInputStream | |
| private final CRC32 | |
| private final boolean | |
| private boolean | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private final InputStream | |
| private Inflater | |
| private final byte[] | |
| private final GzipParameters |
| Access | Constructor and Description |
|---|---|
| public | GzipCompressorInputStream(final InputStream
the InputStream from which this object should be created of inputStream)Constructs a new input stream that decompresses gzip-compressed data from the specified input stream. |
| public | GzipCompressorInputStream(final InputStream
the InputStream from which this object should be created of inputStream, final boolean if true, decompress until the end of the input; if false, stop after the first .gz member decompressConcatenated)Constructs a new input stream that decompresses gzip-compressed data from the specified input stream. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. |
| public long | getCompressedCount()
Implements org. |
| public GzipParameters | Returns: the stream's meta dataProvides the stream's meta data - may change with each stream when decompressing concatenated streams. |
| private boolean | |
| public static boolean | Returns: true if this is a .gz stream, false otherwisethe bytes to check signature, final int the number of bytes to check length)Checks if the signature matches what is expected for a .gz file. |
| public int | read()
Implements abstract java. |
| public int | read(final byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. len bytes of data from the input stream into
an array of bytes.
|
| private static byte[] |
| buf | back to summary |
|---|---|
| private final byte[] buf | |
| bufUsed | back to summary |
|---|---|
| private int bufUsed | |
| countingStream | back to summary |
|---|---|
| private final CountingInputStream countingStream | |
| crc | back to summary |
|---|---|
| private final CRC32 crc | |
| decompressConcatenated | back to summary |
|---|---|
| private final boolean decompressConcatenated | |
| endReached | back to summary |
|---|---|
| private boolean endReached | |
| FCOMMENT | back to summary |
|---|---|
| private static final int FCOMMENT | |
| FEXTRA | back to summary |
|---|---|
| private static final int FEXTRA | |
| FHCRC | back to summary |
|---|---|
| private static final int FHCRC | |
| FNAME | back to summary |
|---|---|
| private static final int FNAME | |
| FRESERVED | back to summary |
|---|---|
| private static final int FRESERVED | |
| in | back to summary |
|---|---|
| private final InputStream in | |
| inf | back to summary |
|---|---|
| private Inflater inf | |
| oneByte | back to summary |
|---|---|
| private final byte[] oneByte | |
| parameters | back to summary |
|---|---|
| private final GzipParameters parameters | |
| GzipCompressorInputStream | back to summary |
|---|---|
| public GzipCompressorInputStream(final InputStream inputStream) throws IOException Constructs a new input stream that decompresses gzip-compressed data from the specified input stream.
This is equivalent to
| |
| GzipCompressorInputStream | back to summary |
|---|---|
| public GzipCompressorInputStream(final InputStream inputStream, final boolean decompressConcatenated) throws IOException Constructs a new input stream that decompresses gzip-compressed data from the specified input stream.
If
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes the input stream (unless it is System.in).
| |
| getCompressedCount | back to summary |
|---|---|
| public long getCompressedCount() Implements org. Doc from org. Gets the amount of raw or compressed bytes read by the stream.
| |
| getMetaData | back to summary |
|---|---|
| public GzipParameters getMetaData() Provides the stream's meta data - may change with each stream when decompressing concatenated streams.
| |
| init | back to summary |
|---|---|
| private boolean init(final boolean isFirstMember) throws IOException | |
| matches | back to summary |
|---|---|
| public static boolean matches(final byte[] signature, final int length) Checks if the signature matches what is expected for a .gz file.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| readToNull | back to summary |
|---|---|
| private static byte[] readToNull(final DataInput inData) throws IOException | |