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
ConstructorsConstructorDescriptionHeapBufferedAsyncEntityConsumer(int bufferLimit) Creates a new instance of this consumer with the provided buffer limit. -
Method Summary
Modifier and TypeMethodDescriptionprotected intTriggered to obtain the capacity increment.protected voiddata(ByteBuffer src, boolean endOfStream) Triggered to pass incoming data packet to the data consumer.protected byte[]Triggered to generate entity representation.intGet the limit of the buffer.voidRelease 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, streamStartMethods inherited from class org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer
consume, streamEnd, updateCapacityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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- ifbufferLimitis 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:
streamStartin classorg.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>- Parameters:
contentType- the entity content type- Throws:
org.apache.hc.core5.http.HttpExceptionIOException
-
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
Triggered 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:
IOException
-
generateContent
Triggered to generate entity representation.- Specified by:
generateContentin classorg.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer<byte[]>- Returns:
- the entity content
- Throws:
IOException
-
releaseResources
public void releaseResources()Release resources being held
-