java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.InflaterInputStream
net.i2p.util.ResettableGZIPInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
ReusableGZIPInputStream
GZIP implementation per RFC 1952, reusing java's standard CRC32 and Inflater and InflaterInputStream implementations. The main difference is that this implementation allows its state to be reset to initial values, and hence reused, while the standard GZIPInputStream reads the GZIP header from the stream on instantiation.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classEssentially a SequenceInputStream(in, new ByteArrayInputStream(new byte[1])), except that this is resettable.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]A one byte buffer for single reads.private booleanTrue once the stream is fully read.private final CRC32The checksum of the data read.private final ResettableGZIPInputStream.ExtraByteInputStreamSee below for why this is necessary.private final LookaheadInputStreamKeep a typesafe copy of this.private static final intSize of the gzip footer, the crc and the size.Fields inherited from class InflaterInputStream
buf, inf, lenFields inherited from class FilterInputStream
inConstructor Summary
ConstructorsConstructorDescriptionBuild a new GZIP stream without a bound compressed stream.ResettableGZIPInputStream(InputStream compressedStream) Warning - blocking!Method Summary
Modifier and TypeMethodDescriptionvoidclose()Does NOT call super.close(), as it cannot be reused if we do that.voiddestroy()Calls super.close().booleanMoved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.longMoved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.longMoved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.longMoved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.final voidinitialize(InputStream compressedStream) Blocking call to initialize this stream with the data from the given compressed stream.intread()intread(byte[] buf) intread(byte[] buf, int off, int len) Read up to len bytes of uncompressed data into the given buffer.toString()Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.private voidChecks the footer of the stream.private voidMake sure the header is valid, throwing an IOException if its b0rked.Methods inherited from class InflaterInputStream
available, fill, mark, markSupported, reset, skipMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Field Details
FOOTER_SIZE
private static final int FOOTER_SIZESize of the gzip footer, the crc and the size.- See Also:
_extraByteInputStream
See below for why this is necessary._lookaheadStream
Keep a typesafe copy of this._crc32
The checksum of the data read._buf1
private final byte[] _buf1A one byte buffer for single reads._complete
private boolean _completeTrue once the stream is fully read.
Constructor Details
ResettableGZIPInputStream
public ResettableGZIPInputStream()Build a new GZIP stream without a bound compressed stream. You need to initialize this with initialize(compressedStream) when you want to decompress a stream.ResettableGZIPInputStream
Warning - blocking!- Parameters:
compressedStream- the GZIP member to decompress, read from on demand- Throws:
IOException- if the GZIP header cannot be read or does not carry the magic bytes, compression method and flags this decoder requires
Method Details
initialize
Blocking call to initialize this stream with the data from the given compressed stream.- Parameters:
compressedStream- the GZIP member to decompress, read from on demand- Throws:
IOException- if the stream ends inside the GZIP header, or the header carries the wrong magic bytes, compression method or extended flags
read
- Overrides:
readin classInflaterInputStream- Throws:
IOException
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
read
Read up to len bytes of uncompressed data into the given buffer.- Overrides:
readin classInflaterInputStream- Throws:
IOException
getTotalRead
public long getTotalRead()Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.- Returns:
- the total read
getTotalExpanded
public long getTotalExpanded()Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.- Returns:
- the total expanded
getRemaining
public long getRemaining()Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.- Returns:
- uncompressed bytes still buffered, or 0 if the inflater has been closed
getFinished
public boolean getFinished()Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.- Returns:
- true once the whole stream has been inflated, false if the inflater has been closed
destroy
Calls super.close(). May not be reused after this.- Throws:
IOException- if the underlying inflater cannot be shut down
close
Does NOT call super.close(), as it cannot be reused if we do that. Broken before 0.9.20.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInflaterInputStream- Throws:
IOException
toString
verifyHeader
Make sure the header is valid, throwing an IOException if its b0rked.- Throws:
IOException- if the magic bytes or compression method are wrong, or the stream ends mid-header