Class DeflatingBrotliEntityProducer
- java.lang.Object
-
- org.apache.hc.client5.http.async.methods.DeflatingBrotliEntityProducer
-
- All Implemented Interfaces:
org.apache.hc.core5.http.EntityDetails,org.apache.hc.core5.http.nio.AsyncDataProducer,org.apache.hc.core5.http.nio.AsyncEntityProducer,org.apache.hc.core5.http.nio.ResourceHolder
public final class DeflatingBrotliEntityProducer extends java.lang.Object implements org.apache.hc.core5.http.nio.AsyncEntityProducerAsyncEntityProducerthat Brotli-compresses bytes from an upstream producer on the fly and writes the compressed stream to the targetDataStreamChannel.Purely async/streaming: no
InputStream/OutputStream. Back-pressure is honored viaavailable()and the I/O reactor?s calls intoproduce(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: -1andchunked=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 directByteBuffers to reduce allocation churn. Native resources are released inreleaseResources().Ensure
Brotli4jLoader.ensureAvailability()has been called once at startup; this class also invokes it in a static initializer as a safeguard.- Since:
- 5.6
- See Also:
AsyncEntityProducer,DataStreamChannel,EncoderJNI
-
-
Constructor Summary
Constructors Constructor Description DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream)Create a producer with sensible defaults (quality=5,lgwin=22,GENERIC).DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream, int quality, int lgwin, int modeInt)Convenience constructor mapping0=GENERIC, 1=TEXT, 2=FONT.DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream, int quality, int lgwin, com.aayushatharva.brotli4j.encoder.Encoder.Mode mode)Create a producer with explicit Brotli params.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidfailed(java.lang.Exception cause)java.lang.StringgetContentEncoding()longgetContentLength()java.lang.StringgetContentType()java.util.Set<java.lang.String>getTrailerNames()booleanisChunked()booleanisRepeatable()voidproduce(org.apache.hc.core5.http.nio.DataStreamChannel channel)voidreleaseResources()
-
-
-
Constructor Detail
-
DeflatingBrotliEntityProducer
public DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream, int quality, int lgwin, com.aayushatharva.brotli4j.encoder.Encoder.Mode mode) throws java.io.IOExceptionCreate a producer with explicit Brotli params.- Parameters:
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)- Throws:
java.io.IOException- if the native encoder cannot be created- Since:
- 5.6
-
DeflatingBrotliEntityProducer
public DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream, int quality, int lgwin, int modeInt) throws java.io.IOExceptionConvenience constructor mapping0=GENERIC, 1=TEXT, 2=FONT.- Throws:
java.io.IOException- Since:
- 5.6
-
DeflatingBrotliEntityProducer
public DeflatingBrotliEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer upstream) throws java.io.IOExceptionCreate a producer with sensible defaults (quality=5,lgwin=22,GENERIC).- Throws:
java.io.IOException- Since:
- 5.6
-
-
Method Detail
-
getContentType
public java.lang.String getContentType()
- Specified by:
getContentTypein interfaceorg.apache.hc.core5.http.EntityDetails
-
getContentEncoding
public java.lang.String getContentEncoding()
- Specified by:
getContentEncodingin interfaceorg.apache.hc.core5.http.EntityDetails
-
getContentLength
public long getContentLength()
- Specified by:
getContentLengthin interfaceorg.apache.hc.core5.http.EntityDetails
-
isChunked
public boolean isChunked()
- Specified by:
isChunkedin interfaceorg.apache.hc.core5.http.EntityDetails
-
getTrailerNames
public java.util.Set<java.lang.String> getTrailerNames()
- Specified by:
getTrailerNamesin interfaceorg.apache.hc.core5.http.EntityDetails
-
isRepeatable
public boolean isRepeatable()
- Specified by:
isRepeatablein interfaceorg.apache.hc.core5.http.nio.AsyncEntityProducer
-
available
public int available()
- Specified by:
availablein interfaceorg.apache.hc.core5.http.nio.AsyncDataProducer
-
produce
public void produce(org.apache.hc.core5.http.nio.DataStreamChannel channel) throws java.io.IOException- Specified by:
producein interfaceorg.apache.hc.core5.http.nio.AsyncDataProducer- Throws:
java.io.IOException
-
failed
public void failed(java.lang.Exception cause)
- Specified by:
failedin interfaceorg.apache.hc.core5.http.nio.AsyncEntityProducer
-
releaseResources
public void releaseResources()
- Specified by:
releaseResourcesin interfaceorg.apache.hc.core5.http.nio.ResourceHolder
-
-