public final class DeflatingBrotliEntityProducer extends Object implements AsyncEntityProducer
AsyncEntityProducer that Brotli-compresses bytes from an upstream producer
on the fly and writes the compressed stream to the target DataStreamChannel.
Purely async/streaming: no InputStream/OutputStream. Back-pressure is
honored via available() and the I/O reactor’s calls into produce(DataStreamChannel).
Trailers from the upstream producer are preserved and emitted once the compressed output
has been fully drained.
Content metadata
ReturnsContent-Encoding: br, Content-Length: -1 and chunked=true.
Repeatability matches the upstream producer.
Implementation notes
Uses Brotli4j’sEncoderJNI.Wrapper. JNI-owned output buffers are written directly
when possible; if the channel applies back-pressure, the unwritten tail is copied into
small pooled direct ByteBuffers to reduce allocation churn. Native
resources are released in releaseResources().
Ensure Brotli4jLoader.ensureAvailability() has been
called once at startup; this class also invokes it in a static initializer as a safeguard.
AsyncEntityProducer,
DataStreamChannel,
EncoderJNI| Constructor and Description |
|---|
DeflatingBrotliEntityProducer(AsyncEntityProducer upstream)
Create a producer with sensible defaults (
quality=5, lgwin=22, GENERIC). |
DeflatingBrotliEntityProducer(AsyncEntityProducer upstream,
int quality,
int lgwin,
com.aayushatharva.brotli4j.encoder.Encoder.Mode mode)
Create a producer with explicit Brotli params.
|
DeflatingBrotliEntityProducer(AsyncEntityProducer upstream,
int quality,
int lgwin,
int modeInt)
Convenience constructor mapping
0=GENERIC, 1=TEXT, 2=FONT. |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
failed(Exception cause) |
String |
getContentEncoding() |
long |
getContentLength() |
String |
getContentType() |
Set<String> |
getTrailerNames() |
boolean |
isChunked() |
boolean |
isRepeatable() |
void |
produce(DataStreamChannel channel) |
void |
releaseResources() |
public DeflatingBrotliEntityProducer(AsyncEntityProducer upstream, int quality, int lgwin, com.aayushatharva.brotli4j.encoder.Encoder.Mode mode) throws IOException
upstream - upstream entity producer whose bytes will be compressedquality - Brotli quality level (see brotli4j documentation)lgwin - Brotli window size log2 (see brotli4j documentation)mode - Brotli mode hint (GENERIC/TEXT/FONT)IOException - if the native encoder cannot be createdpublic DeflatingBrotliEntityProducer(AsyncEntityProducer upstream, int quality, int lgwin, int modeInt) throws IOException
0=GENERIC, 1=TEXT, 2=FONT.IOExceptionpublic DeflatingBrotliEntityProducer(AsyncEntityProducer upstream) throws IOException
quality=5, lgwin=22, GENERIC).IOExceptionpublic String getContentType()
getContentType in interface EntityDetailspublic String getContentEncoding()
getContentEncoding in interface EntityDetailspublic long getContentLength()
getContentLength in interface EntityDetailspublic boolean isChunked()
isChunked in interface EntityDetailspublic Set<String> getTrailerNames()
getTrailerNames in interface EntityDetailspublic boolean isRepeatable()
isRepeatable in interface AsyncEntityProducerpublic int available()
available in interface AsyncDataProducerpublic void produce(DataStreamChannel channel) throws IOException
produce in interface AsyncDataProducerIOExceptionpublic void failed(Exception cause)
failed in interface AsyncEntityProducerpublic void releaseResources()
releaseResources in interface ResourceHolderCopyright © 1999–2021 The Apache Software Foundation. All rights reserved.