Class InflatingBrotliDataConsumer

  • All Implemented Interfaces:
    org.apache.hc.core5.http.nio.AsyncDataConsumer, org.apache.hc.core5.http.nio.ResourceHolder

    public final class InflatingBrotliDataConsumer
    extends java.lang.Object
    implements org.apache.hc.core5.http.nio.AsyncDataConsumer
    AsyncDataConsumer that inflates a Brotli-compressed byte stream and forwards decompressed bytes to a downstream consumer.

    Purely async/streaming: no InputStream/OutputStream. Back-pressure from the I/O reactor is propagated via CapacityChannel. JNI output buffers are copied into small reusable direct ByteBuffers before handing them to the downstream consumer (which may retain them).

    Implementation notes

    Uses Brotli4j’s DecoderJNI.Wrapper. Native resources are released in releaseResources(). Throws an IOException if the stream is truncated or corrupted.

    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:
    AsyncDataConsumer, CapacityChannel, DecoderJNI
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.hc.core5.http.nio.CapacityChannel capacity  
      private com.aayushatharva.brotli4j.decoder.DecoderJNI.Wrapper decoder  
      private org.apache.hc.core5.http.nio.AsyncDataConsumer downstream  
    • Constructor Summary

      Constructors 
      Constructor Description
      InflatingBrotliDataConsumer​(org.apache.hc.core5.http.nio.AsyncDataConsumer downstream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void consume​(java.nio.ByteBuffer src)  
      private void pump()  
      void releaseResources()  
      void streamEnd​(java.util.List<? extends org.apache.hc.core5.http.Header> trailers)  
      void updateCapacity​(org.apache.hc.core5.http.nio.CapacityChannel capacityChannel)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • downstream

        private final org.apache.hc.core5.http.nio.AsyncDataConsumer downstream
      • decoder

        private final com.aayushatharva.brotli4j.decoder.DecoderJNI.Wrapper decoder
      • capacity

        private volatile org.apache.hc.core5.http.nio.CapacityChannel capacity
    • Constructor Detail

      • InflatingBrotliDataConsumer

        public InflatingBrotliDataConsumer​(org.apache.hc.core5.http.nio.AsyncDataConsumer downstream)
    • Method Detail

      • updateCapacity

        public void updateCapacity​(org.apache.hc.core5.http.nio.CapacityChannel capacityChannel)
                            throws java.io.IOException
        Specified by:
        updateCapacity in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
        Throws:
        java.io.IOException
      • consume

        public void consume​(java.nio.ByteBuffer src)
                     throws java.io.IOException
        Specified by:
        consume in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
        Throws:
        java.io.IOException
      • streamEnd

        public void streamEnd​(java.util.List<? extends org.apache.hc.core5.http.Header> trailers)
                       throws java.io.IOException,
                              org.apache.hc.core5.http.HttpException
        Specified by:
        streamEnd in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
        Throws:
        java.io.IOException
        org.apache.hc.core5.http.HttpException
      • releaseResources

        public void releaseResources()
        Specified by:
        releaseResources in interface org.apache.hc.core5.http.nio.ResourceHolder
      • pump

        private void pump()
                   throws java.io.IOException
        Throws:
        java.io.IOException