- All Known Subinterfaces:
FeedableHttpEntity
An entity that can be sent or received via an
HttpRequest or HttpResponse.
There are three distinct types of entities, depending on their content:
- streamed: The content is received from a stream.
- composed: The content is made of several parts.
- neither of the above: The content is in memory and whole.
- Since:
- 0.12.0
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]getBytes()Provides the entity's content as bytes.Provides the length (in bytes) of theHttpEntity, if known.Provides the entity's content as a stream.default booleanbooleanTells whether this entity's content is stream-based.default voidonComplete(BiConsumer<? super org.mule.runtime.api.util.MultiMap<String, String>, ? super Throwable> completionCallback) To be called when the trailers are received, or when we know that we aren't going to receive any trailers.default EntitySubscriptiononData(Consumer<ByteBuffer> dataConsumer) Handle each fragment of data.
-
Method Details
-
isStreaming
boolean isStreaming()Tells whether this entity's content is stream-based. Streamed entities can only provide their content once, regardless of the access method.- Returns:
trueif content is streamed,falseotherwise- See Also:
-
getContent
InputStream getContent()Provides the entity's content as a stream. All streaming entities should provide their stream.- Returns:
- an
InputStreamrepresenting this entity's content ornullif such representation is not possible
-
getBytes
Provides the entity's content as bytes. If the entity is stream based, then the stream will be consumed as a consequence.- Returns:
- a byte array representing this entity's content or
nullif such representation is not possible - Throws:
IOException- if an error occurs creating the byte array
-
getBytesLength
OptionalLong getBytesLength()Provides the length (in bytes) of theHttpEntity, if known. For the most part, only received entities from HTTP messages that carried a 'Content-Length' header will return a length.- Returns:
- an
Optionalwith the length (in bytes) or an empty one if unknown
-
onComplete
default void onComplete(BiConsumer<? super org.mule.runtime.api.util.MultiMap<String, String>, ? super Throwable> completionCallback) To be called when the trailers are received, or when we know that we aren't going to receive any trailers. In that case, the parameter of the consumer will be an emptyMultiMap. For example, for HTTP/1 messages, we know that we will never receive trailers, so this callback will be preemptively invoked.- Parameters:
completionCallback- callback to be invoked.- Since:
- 0.13.0
-
onData
Handle each fragment of data.- Parameters:
dataConsumer- callback to be executed for each data fragment seen in the entity.- Returns:
- a
EntitySubscriptionobject that can be used to cancel the reactive consumption of the entity. - Throws:
UnsupportedOperationException- if the implementation doesn't support reactive consumption.- Since:
- 0.13.0
-
isReactive
default boolean isReactive()- Returns:
- whether this entity supports consuming data fragments reactively, by using
onData(Consumer) - Since:
- 0.13.0
- See Also:
-