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 ofAsyncEntityConsumer. 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 intcapacityIncrement()Triggered to obtain the capacity increment.protected voiddata(java.nio.ByteBuffer src, boolean endOfStream)Triggered to pass incoming data packet to the data consumer.protected byte[]generateContent()Triggered to generate entity representation.intgetBufferLimit()Get the limit of the buffer.voidreleaseResources()Release resources being heldprotected voidstreamStart(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
-
-
-
-
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- ifbufferLimitis 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.IOExceptionTriggered to signal beginning of entity content stream.- Specified by:
streamStartin classorg.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>- Parameters:
contentType- the entity content type- Throws:
org.apache.hc.core5.http.HttpExceptionjava.io.IOException
-
capacityIncrement
protected int capacityIncrement()
Triggered to obtain the capacity increment.- Specified by:
capacityIncrementin classorg.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.IOExceptionTriggered to pass incoming data packet to the data consumer.- Specified by:
datain classorg.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.IOExceptionTriggered to generate entity representation.- Specified by:
generateContentin classorg.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>- Returns:
- the entity content
- Throws:
java.io.IOException
-
releaseResources
public void releaseResources()
Release resources being held
-
-