Interface TypedApiEntityConsumer<T>
- Type Parameters:
T- the type of the entity expected in the successful response
- All Known Implementing Classes:
TypedApiEntityConsumer.JsonApiEntityConsumer,TypedApiEntityConsumer.RawApiEntityConsumer
public interface TypedApiEntityConsumer<T>
A generic interface for consuming API entities from an asynchronous data stream. This interface
defines the basic operations required by
ApiEntityConsumer to handle different types of
API responses, including JSON and raw byte data.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classATypedApiEntityConsumerimplementation for handling JSON data.static classATypedApiEntityConsumerimplementation for handling raw data, which could be text or binary. -
Method Summary
Modifier and TypeMethodDescriptionvoidconsumeData(ByteBuffer src, boolean endOfStream) Consumes data from the providedByteBuffer.Generates the final content after all data has been consumed.intReturns the number of bytes currently buffered by this consumer.voidReleases any resources associated with this consumer.
-
Method Details
-
generateContent
Generates the final content after all data has been consumed.- Returns:
- an
ApiEntitycontaining the deserialized content, or null if no data was consumed - Throws:
IOException
-
consumeData
Consumes data from the providedByteBuffer. This method is called as data becomes available and can be invoked multiple times as more data is streamed.- Parameters:
src- theByteBuffercontaining the data to be consumedendOfStream- a flag indicating whether this is the last chunk of data- Throws:
IOException
-
releaseResources
void releaseResources()Releases any resources associated with this consumer. This method should be called once the consumer is no longer needed, such as after the response has been fully processed. -
getBufferedBytes
int getBufferedBytes()Returns the number of bytes currently buffered by this consumer.- Returns:
- the number of buffered bytes
-