Class GZIPContentDecoder
- All Implemented Interfaces:
Destroyable
- Direct Known Subclasses:
GZIPContentDecoder
Decoder for the "gzip" content encoding.
This decoder inflates gzip compressed data, and has been optimized for async usage with minimal data copies.
-
Constructor Summary
ConstructorDescriptionGZIPContentDecoder
(int bufferSize) GZIPContentDecoder
(ByteBufferPool pool, int bufferSize) GZIPContentDecoder
(ByteBufferPool pool, int bufferSize, boolean useDirectBuffers) GZIPContentDecoder
(InflaterPool inflaterPool, ByteBufferPool pool, int bufferSize) GZIPContentDecoder
(InflaterPool inflaterPool, ByteBufferPool pool, int bufferSize, boolean useDirectBuffers) -
Method Summary
Modifier and TypeMethodDescriptionacquire
(int capacity) decode
(ByteBuffer compressed) Inflates compressed data from a buffer.protected void
decodeChunks
(ByteBuffer compressed) Inflates compressed data.protected boolean
decodedChunk
(ByteBuffer chunk) Called when a chunk of data is inflated.void
destroy()
boolean
void
release
(ByteBuffer buffer) Releases an allocated buffer.
-
Constructor Details
-
GZIPContentDecoder
public GZIPContentDecoder() -
GZIPContentDecoder
public GZIPContentDecoder(int bufferSize) -
GZIPContentDecoder
-
GZIPContentDecoder
-
GZIPContentDecoder
-
GZIPContentDecoder
public GZIPContentDecoder(InflaterPool inflaterPool, ByteBufferPool pool, int bufferSize, boolean useDirectBuffers)
-
-
Method Details
-
decode
Inflates compressed data from a buffer.
The buffers returned by this method should be released via
release(ByteBuffer)
.This method may fully consume the input buffer, but return only a chunk of the inflated bytes, to allow applications to consume the inflated chunk before performing further inflation, applying backpressure. In this case, this method should be invoked again with the same input buffer (even if it's already fully consumed) and that will produce another chunk of inflated bytes. Termination happens when the input buffer is fully consumed, and the returned buffer is empty.
See
decodedChunk(ByteBuffer)
to perform inflating in a non-blocking way that allows to apply backpressure.- Parameters:
compressed
- the buffer containing compressed data.- Returns:
- a buffer containing inflated data.
-
decodedChunk
Called when a chunk of data is inflated.
The default implementation aggregates all the chunks into a single buffer returned from
decode(ByteBuffer)
.Derived implementations may choose to consume inflated chunks individually and return
true
from this method to prevent further inflation until a subsequent call todecode(ByteBuffer)
ordecodeChunks(ByteBuffer)
is made.- Parameters:
chunk
- the inflated chunk of data- Returns:
- false if inflating should continue, or true if the call
to
decodeChunks(ByteBuffer)
ordecode(ByteBuffer)
should return, allowing to consume the inflated chunk and apply backpressure
-
decodeChunks
Inflates compressed data.
Inflation continues until the compressed block end is reached, there is no more compressed data or a call to
decodedChunk(ByteBuffer)
returns true.- Parameters:
compressed
- the buffer of compressed data to inflate
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDestroyable
-
isFinished
public boolean isFinished() -
acquire
- Parameters:
capacity
- capacity of the ByteBuffer to acquire- Returns:
- a heap buffer of the configured capacity either from the pool or freshly allocated.
-
release
Releases an allocated buffer.
This method calls
ByteBufferPool.release(ByteBuffer)
if a buffer pool has been configured.This method should be called once for all buffers returned from
decode(ByteBuffer)
or passed todecodedChunk(ByteBuffer)
.- Parameters:
buffer
- the buffer to release.
-