- Type Parameters:
T- the response body type
public static interface HttpResponse.BodySubscriber<T> extends Flow.Subscriber<List<ByteBuffer>>A
BodySubscriberconsumes response body bytes and converts them into a higher-level Java type. The class
BodySubscriberprovides implementations of many common body subscribers.
The object acts as a
ByteBuffer>> to the HTTP client implementation, which publishes unmodifiable lists of read-only 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 type
getBody()method returns a
T> that provides the response body object. The
CompletionStagemust be obtainable at any time. When it completes depends on the nature of type
T. In many cases, when
Trepresents the entire body after being consumed then the
CompletionStagecompletes after the body has been consumed. If
Tis a streaming type, such as
InputStream, then it completes before the body has been read, because the calling code uses the
InputStreamto consume the data.
- API Note:
- To ensure that all resources associated with the corresponding
HTTP exchange are properly released, an implementation of
BodySubscribershould ensure to
requestmore data until one of
onErrorare signalled, or
cancelits subscription if unable or unwilling to do so. Calling
cancelbefore exhausting the response body data may cause the underlying HTTP connection to be closed and prevent it from being reused for subsequent operations.
- See Also:
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
CompletionStagewhich when completed will return the response body object.