-
- Type Parameters:
T
- the response body type
- All Superinterfaces:
Flow.Subscriber<List<ByteBuffer>>
- Enclosing interface:
- HttpResponse<T>
public static interface HttpResponse.BodySubscriber<T> extends Flow.Subscriber<List<ByteBuffer>>
ABodySubscriber
consumes response body bytes and converts them into a higher-level Java type. The classBodySubscriber
provides implementations of many common body subscribers.The object acts as a
Flow.Subscriber
<List
<ByteBuffer
>> to the HTTP Client implementation, which publishes lists of ByteBuffers containing the response body. The Flow of data, as well as the order of ByteBuffers in the Flow lists, is a strictly ordered representation of the response body. Both the Lists and the ByteBuffers, once passed to the subscriber, are no longer used by the HTTP Client. The subscriber converts the incoming buffers of data to some higher-level Java typeT
.The
getBody()
method returns aCompletionStage
<T>
that provides the response body object. TheCompletionStage
must be obtainable at any time. When it completes depends on the nature of typeT
. In many cases, whenT
represents the entire body after being consumed then theCompletionStage
completes after the body has been consumed. IfT
is a streaming type, such asInputStream
, then it completes before the body has been read, because the calling code uses theInputStream
to consume the data.- API Note:
- To ensure that all resources associated with the corresponding
HTTP exchange are properly released, an implementation of
BodySubscriber
should ensure to request more data until one ofonComplete
oronError
are signalled, orcancel
its subscription if unable or unwilling to do so. Callingcancel
before exhausting the response body data may cause the underlying HTTP connection to be closed and prevent it from being reused for subsequent operations. - Implementation Note:
- The flow of data containing the response body is immutable. Specifically, it is a flow of unmodifiable lists of read-only ByteBuffers.
- Since:
- 11
- See Also:
HttpResponse.BodySubscribers
-
-
Method Summary
Modifier and Type Method Description CompletionStage<T>
getBody()
Returns aCompletionStage
which when completed will return the response body object.-
Methods declared in interface java.util.concurrent.Flow.Subscriber
onComplete, onError, onNext, onSubscribe
-
-
-
-
Method Detail
-
getBody
CompletionStage<T> getBody()
Returns aCompletionStage
which when completed will return the response body object. This method can be called at any time relative to the otherFlow.Subscriber
methods and is invoked using the client'sexecutor
.- Returns:
- a CompletionStage for the response body
-
-