All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ReusableGZIPInputStream

public class ResettableGZIPInputStreamextends InflaterInputStream
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.
  • Field Details

    • _extraByteInputStream

      private final ResettableGZIPInputStream.ExtraByteInputStream _extraByteInputStream
      See below for why this is necessary.
    • _lookaheadStream

      private final LookaheadInputStream _lookaheadStream
      Keep a typesafe copy of this.
    • _crc32

      private final CRC32 _crc32
      The checksum of the data read.
    • _buf1

      private final byte[] _buf1
      A one byte buffer for single reads.
    • _complete

      private boolean _complete
      True 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

      public ResettableGZIPInputStream(InputStream compressedStream) throws IOException
      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

      public final void initialize(InputStream compressedStream) throws IOException
      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

      public int read() throws IOException
      Overrides:
      read in class InflaterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] buf) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] buf, int off, int len) throws IOException
      Read up to len bytes of uncompressed data into the given buffer.
      Overrides:
      read in class InflaterInputStream
      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

      public void destroy() throws IOException
      Calls super.close(). May not be reused after this.
      Throws:
      IOException - if the underlying inflater cannot be shut down
    • close

      public void close() throws IOException
      Does NOT call super.close(), as it cannot be reused if we do that. Broken before 0.9.20.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InflaterInputStream
      Throws:
      IOException
    • toString

      public String toString()
      Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream.
      Overrides:
      toString in class Object
    • verifyFooter

      private void verifyFooter() throws IOException
      Checks the footer of the stream.
      Throws:
      IOException - if the footer does not match
    • verifyHeader

      private void verifyHeader() throws IOException
      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