Class GzipInflatingBuffer

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @NotThreadSafe
    class GzipInflatingBuffer
    extends java.lang.Object
    implements java.io.Closeable
    Processes gzip streams, delegating to Inflater to perform on-demand inflation of the deflated blocks. Like GZIPInputStream, this handles concatenated gzip streams. Unlike GZIPInputStream, this allows for incremental processing of gzip streams, allowing data to be inflated as it arrives over the wire.

    This also frees the inflate context when the end of a gzip stream is reached without another concatenated stream available to inflate.

    • Field Detail

      • crc

        private final java.util.zip.CRC32 crc
      • inflaterInput

        private final byte[] inflaterInput
      • inflaterInputStart

        private int inflaterInputStart
      • inflaterInputEnd

        private int inflaterInputEnd
      • inflater

        private java.util.zip.Inflater inflater
      • closed

        private boolean closed
      • gzipHeaderFlag

        private int gzipHeaderFlag
        Extra state variables for parsing gzip header flags.
      • headerExtraToRead

        private int headerExtraToRead
      • expectedGzipTrailerIsize

        private long expectedGzipTrailerIsize
      • bytesConsumed

        private int bytesConsumed
        Tracks gzipped bytes (including gzip metadata and deflated blocks) consumed during inflateBytes(byte[], int, int) calls.
      • deflatedBytesConsumed

        private int deflatedBytesConsumed
        Tracks deflated bytes (excluding gzip metadata) consumed by the inflater.
      • isStalled

        private boolean isStalled
    • Constructor Detail

      • GzipInflatingBuffer

        GzipInflatingBuffer()
    • Method Detail

      • hasPartialData

        boolean hasPartialData()
        Returns true when there is gzippedData that has not been input to the inflater or the inflater has not consumed all of its input, or all data has been consumed but we are at not at the boundary between gzip streams.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getAndResetBytesConsumed

        int getAndResetBytesConsumed()
        Reports bytes consumed by calls to inflateBytes(byte[], int, int) since the last invocation of this method, then resets the count to zero.
      • getAndResetDeflatedBytesConsumed

        int getAndResetDeflatedBytesConsumed()
        Reports bytes consumed by the inflater since the last invocation of this method, then resets the count to zero.
      • inflateBytes

        int inflateBytes​(byte[] b,
                         int offset,
                         int length)
                  throws java.util.zip.DataFormatException,
                         java.util.zip.ZipException
        Attempts to inflate length bytes of data into b.

        Any gzipped bytes consumed by this method will be added to the counter returned by getAndResetBytesConsumed(). This method may consume gzipped bytes without writing any data to b, and may also write data to b without consuming additional gzipped bytes (if the inflater on an earlier call consumed the bytes necessary to produce output).

        Parameters:
        b - the destination array to receive the bytes.
        offset - the starting offset in the destination array.
        length - the number of bytes to be copied.
        Throws:
        java.lang.IndexOutOfBoundsException - if b is too small to hold the requested bytes.
        java.util.zip.DataFormatException
        java.util.zip.ZipException
      • processHeader

        private boolean processHeader()
                               throws java.util.zip.ZipException
        Throws:
        java.util.zip.ZipException
      • processHeaderExtraLen

        private boolean processHeaderExtraLen()
      • processHeaderExtra

        private boolean processHeaderExtra()
      • processHeaderName

        private boolean processHeaderName()
      • processHeaderComment

        private boolean processHeaderComment()
      • processHeaderCrc

        private boolean processHeaderCrc()
                                  throws java.util.zip.ZipException
        Throws:
        java.util.zip.ZipException
      • initializeInflater

        private boolean initializeInflater()
      • inflate

        private int inflate​(byte[] b,
                            int off,
                            int len)
                     throws java.util.zip.DataFormatException,
                            java.util.zip.ZipException
        Throws:
        java.util.zip.DataFormatException
        java.util.zip.ZipException
      • fill

        private boolean fill()
      • processTrailer

        private boolean processTrailer()
                                throws java.util.zip.ZipException
        Throws:
        java.util.zip.ZipException