Package io.grpc.internal
Class GzipInflatingBuffer
java.lang.Object
io.grpc.internal.GzipInflatingBuffer
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Reads gzip header and trailer bytes from the inflater's buffer (if bytes beyond the inflate block were given to the inflater) and then fromgzippedData
, and handles updating the CRC and the count of gzipped bytes consumed.private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Tracks gzipped bytes (including gzip metadata and deflated blocks) consumed duringinflateBytes(byte[], int, int)
calls.private boolean
private final CRC32
private int
Tracks deflated bytes (excluding gzip metadata) consumed by the inflater.private long
private static final int
private static final int
private static final int
private int
Extra state variables for parsing gzip header flags.private final GzipInflatingBuffer.GzipMetadataReader
private final CompositeReadableBuffer
This buffer holds all input gzipped data, consisting of blocks of deflated data and the surrounding gzip headers and trailers.private static final int
private static final int
private static final int
private static final int
private int
private static final int
private Inflater
private final byte[]
private int
private int
private boolean
private GzipInflatingBuffer.State
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
addGzippedBytes
(ReadableBuffer buffer) Adds more gzipped data, which will be consumed only when needed to fulfill requests made viainflateBytes(byte[], int, int)
.void
close()
private boolean
fill()
(package private) int
Reports bytes consumed by calls toinflateBytes(byte[], int, int)
since the last invocation of this method, then resets the count to zero.(package private) int
Reports bytes consumed by the inflater since the last invocation of this method, then resets the count to zero.(package private) boolean
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.private int
inflate
(byte[] b, int off, int len) (package private) int
inflateBytes
(byte[] b, int offset, int length) Attempts to inflatelength
bytes of data intob
.private boolean
(package private) boolean
Returns true when more bytes must be added viaaddGzippedBytes(io.grpc.internal.ReadableBuffer)
to enable additional calls toinflateBytes(byte[], int, int)
to make progress.private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
-
Field Details
-
INFLATE_BUFFER_SIZE
private static final int INFLATE_BUFFER_SIZE- See Also:
-
UNSIGNED_SHORT_SIZE
private static final int UNSIGNED_SHORT_SIZE- See Also:
-
GZIP_MAGIC
private static final int GZIP_MAGIC- See Also:
-
GZIP_HEADER_MIN_SIZE
private static final int GZIP_HEADER_MIN_SIZE- See Also:
-
GZIP_TRAILER_SIZE
private static final int GZIP_TRAILER_SIZE- See Also:
-
HEADER_CRC_FLAG
private static final int HEADER_CRC_FLAG- See Also:
-
HEADER_EXTRA_FLAG
private static final int HEADER_EXTRA_FLAG- See Also:
-
HEADER_NAME_FLAG
private static final int HEADER_NAME_FLAG- See Also:
-
HEADER_COMMENT_FLAG
private static final int HEADER_COMMENT_FLAG- See Also:
-
gzippedData
This buffer holds all input gzipped data, consisting of blocks of deflated data and the surrounding gzip headers and trailers. All access to the Gzip headers and trailers must be made viaGzipInflatingBuffer.GzipMetadataReader
. -
crc
-
gzipMetadataReader
-
inflaterInput
private final byte[] inflaterInput -
inflaterInputStart
private int inflaterInputStart -
inflaterInputEnd
private int inflaterInputEnd -
inflater
-
state
-
closed
private boolean closed -
gzipHeaderFlag
private int gzipHeaderFlagExtra state variables for parsing gzip header flags. -
headerExtraToRead
private int headerExtraToRead -
expectedGzipTrailerIsize
private long expectedGzipTrailerIsize -
bytesConsumed
private int bytesConsumedTracks gzipped bytes (including gzip metadata and deflated blocks) consumed duringinflateBytes(byte[], int, int)
calls. -
deflatedBytesConsumed
private int deflatedBytesConsumedTracks deflated bytes (excluding gzip metadata) consumed by the inflater. -
isStalled
private boolean isStalled
-
-
Constructor Details
-
GzipInflatingBuffer
GzipInflatingBuffer()
-
-
Method Details
-
isStalled
boolean isStalled()Returns true when more bytes must be added viaaddGzippedBytes(io.grpc.internal.ReadableBuffer)
to enable additional calls toinflateBytes(byte[], int, int)
to make progress. -
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. -
addGzippedBytes
Adds more gzipped data, which will be consumed only when needed to fulfill requests made viainflateBytes(byte[], int, int)
. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getAndResetBytesConsumed
int getAndResetBytesConsumed()Reports bytes consumed by calls toinflateBytes(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
Attempts to inflatelength
bytes of data intob
.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 tob
, and may also write data tob
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:
IndexOutOfBoundsException
- ifb
is too small to hold the requested bytes.DataFormatException
ZipException
-
processHeader
- Throws:
ZipException
-
processHeaderExtraLen
private boolean processHeaderExtraLen() -
processHeaderExtra
private boolean processHeaderExtra() -
processHeaderName
private boolean processHeaderName() -
processHeaderComment
private boolean processHeaderComment() -
processHeaderCrc
- Throws:
ZipException
-
initializeInflater
private boolean initializeInflater() -
inflate
- Throws:
DataFormatException
ZipException
-
fill
private boolean fill() -
processTrailer
- Throws:
ZipException
-