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 classReads 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 intTracks gzipped bytes (including gzip metadata and deflated blocks) consumed duringinflateBytes(byte[], int, int)calls.private booleanprivate final CRC32private intTracks deflated bytes (excluding gzip metadata) consumed by the inflater.private longprivate static final intprivate static final intprivate static final intprivate intExtra state variables for parsing gzip header flags.private final GzipInflatingBuffer.GzipMetadataReaderprivate final CompositeReadableBufferThis buffer holds all input gzipped data, consisting of blocks of deflated data and the surrounding gzip headers and trailers.private static final intprivate static final intprivate static final intprivate static final intprivate intprivate static final intprivate Inflaterprivate final byte[]private intprivate intprivate booleanprivate GzipInflatingBuffer.Stateprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddGzippedBytes(ReadableBuffer buffer) Adds more gzipped data, which will be consumed only when needed to fulfill requests made viainflateBytes(byte[], int, int).voidclose()private booleanfill()(package private) intReports bytes consumed by calls toinflateBytes(byte[], int, int)since the last invocation of this method, then resets the count to zero.(package private) intReports bytes consumed by the inflater since the last invocation of this method, then resets the count to zero.(package private) booleanReturns 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 intinflate(byte[] b, int off, int len) (package private) intinflateBytes(byte[] b, int offset, int length) Attempts to inflatelengthbytes of data intob.private boolean(package private) booleanReturns true when more bytes must be added viaaddGzippedBytes(ReadableBuffer)to enable additional calls toinflateBytes(byte[], int, int)to make progress.private booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate 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(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:
closein interfaceAutoCloseable- Specified by:
closein 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 inflatelengthbytes 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 tobwithout 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- ifbis too small to hold the requested bytes.DataFormatExceptionZipException
-
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:
DataFormatExceptionZipException
-
fill
private boolean fill() -
processTrailer
- Throws:
ZipException
-