Class HeapBufferedAsyncEntityConsumer

java.lang.Object
org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer
org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>
org.opensearch.client.transport.httpclient5.internal.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
    Creates a new instance of this consumer with the provided buffer limit.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    Triggered to obtain the capacity increment.
    protected void
    data(ByteBuffer src, boolean endOfStream)
    Triggered to pass incoming data packet to the data consumer.
    protected byte[]
    Triggered to generate entity representation.
    int
    Get the limit of the buffer.
    void
    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 Details

    • 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:
      IllegalArgumentException - if bufferLimit is less than or equal to 0.
  • Method Details

    • 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, 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
      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(ByteBuffer src, boolean endOfStream) throws 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:
      IOException
    • generateContent

      protected byte[] generateContent() throws 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:
      IOException
    • releaseResources

      public void releaseResources()
      Release resources being held