Class HeapBufferedAsyncEntityConsumer

  • All Implemented Interfaces:
    org.apache.hc.core5.http.nio.AsyncDataConsumer, org.apache.hc.core5.http.nio.AsyncEntityConsumer<byte[]>, org.apache.hc.core5.http.nio.ResourceHolder

    public class HeapBufferedAsyncEntityConsumer
    extends org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>
    Default implementation of AsyncEntityConsumer. Buffers the whole response content in heap memory, meaning that the size of the buffer is equal to the content-length of the response. Limits the size of responses that can be read based on a configurable argument. Throws an exception in case the entity is longer than the configured buffer limit.
    • Constructor Summary

      Constructors 
      Constructor Description
      HeapBufferedAsyncEntityConsumer​(int bufferLimit)
      Creates a new instance of this consumer with the provided buffer limit.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int capacityIncrement()
      Triggered to obtain the capacity increment.
      protected void data​(java.nio.ByteBuffer src, boolean endOfStream)
      Triggered to pass incoming data packet to the data consumer.
      protected byte[] generateContent()
      Triggered to generate entity representation.
      int getBufferLimit()
      Get the limit of the buffer.
      void releaseResources()
      Release resources being held
      protected void streamStart​(org.apache.hc.core5.http.ContentType contentType)
      Triggered to signal beginning of entity content stream.
      • Methods inherited from class org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer

        completed, failed, getContent, streamStart
      • Methods inherited from class org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer

        consume, streamEnd, updateCapacity
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apache.hc.core5.http.nio.AsyncDataConsumer

        consume, streamEnd, updateCapacity
    • Constructor Detail

      • HeapBufferedAsyncEntityConsumer

        public HeapBufferedAsyncEntityConsumer​(int bufferLimit)
        Creates a new instance of this consumer with the provided buffer limit.
        Parameters:
        bufferLimit - the buffer limit. Must be greater than 0.
        Throws:
        java.lang.IllegalArgumentException - if bufferLimit is less than or equal to 0.
    • Method Detail

      • getBufferLimit

        public int getBufferLimit()
        Get the limit of the buffer.
      • streamStart

        protected void streamStart​(org.apache.hc.core5.http.ContentType contentType)
                            throws org.apache.hc.core5.http.HttpException,
                                   java.io.IOException
        Triggered to signal beginning of entity content stream.
        Specified by:
        streamStart in class org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>
        Parameters:
        contentType - the entity content type
        Throws:
        org.apache.hc.core5.http.HttpException
        java.io.IOException
      • capacityIncrement

        protected int capacityIncrement()
        Triggered to obtain the capacity increment.
        Specified by:
        capacityIncrement in class org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer
        Returns:
        the number of bytes this consumer is prepared to process.
      • data

        protected void data​(java.nio.ByteBuffer src,
                            boolean endOfStream)
                     throws java.io.IOException
        Triggered to pass incoming data packet to the data consumer.
        Specified by:
        data in class org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer
        Parameters:
        src - the data packet.
        endOfStream - flag indicating whether this data packet is the last in the data stream.
        Throws:
        java.io.IOException
      • generateContent

        protected byte[] generateContent()
                                  throws java.io.IOException
        Triggered to generate entity representation.
        Specified by:
        generateContent in class org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>
        Returns:
        the entity content
        Throws:
        java.io.IOException
      • releaseResources

        public void releaseResources()
        Release resources being held