public class GZIPContentDecoder extends java.lang.Object implements Destroyable
Decoder for the "gzip" content encoding.
This decoder inflates gzip compressed data, and has been optimized for async usage with minimal data copies.
Constructor and Description |
---|
GZIPContentDecoder() |
GZIPContentDecoder(ByteBufferPool pool,
int bufferSize) |
GZIPContentDecoder(int bufferSize) |
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
acquire(int capacity) |
java.nio.ByteBuffer |
decode(java.nio.ByteBuffer compressed)
Inflates compressed data from a buffer.
|
protected void |
decodeChunks(java.nio.ByteBuffer compressed)
Inflates compressed data.
|
protected boolean |
decodedChunk(java.nio.ByteBuffer chunk)
Called when a chunk of data is inflated.
|
void |
destroy() |
boolean |
isFinished() |
void |
release(java.nio.ByteBuffer buffer)
Releases an allocated buffer.
|
public GZIPContentDecoder()
public GZIPContentDecoder(int bufferSize)
public GZIPContentDecoder(ByteBufferPool pool, int bufferSize)
public java.nio.ByteBuffer decode(java.nio.ByteBuffer compressed)
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.
compressed
- the buffer containing compressed data.protected boolean decodedChunk(java.nio.ByteBuffer chunk)
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 to decode(ByteBuffer)
or decodeChunks(ByteBuffer)
is made.
chunk
- the inflated chunk of datadecodeChunks(ByteBuffer)
or decode(ByteBuffer)
should return, allowing to consume the inflated chunk and apply
backpressureprotected void decodeChunks(java.nio.ByteBuffer compressed)
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.
compressed
- the buffer of compressed data to inflatepublic void destroy()
destroy
in interface Destroyable
public boolean isFinished()
public java.nio.ByteBuffer acquire(int capacity)
capacity
- capacity of the ByteBuffer to acquirepublic void release(java.nio.ByteBuffer buffer)
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 to decodedChunk(ByteBuffer)
.
buffer
- the buffer to release.Copyright © 1995–2022 Webtide. All rights reserved.