T
- the response body typeFlow.Subscriber<ByteBuffer>
public static interface HttpResponse.BodyProcessor<T> extends Flow.Subscriber<ByteBuffer>
Flow.Subscriber
<ByteBuffer
> to the HTTP client implementation
which publishes ByteBuffers containing the response body. The processor
converts the incoming buffers of data to some user-defined object type T
.
The getBody()
method returns a CompletionStage
<T>
that provides the response body object. The CompletionStage
must
be obtainable at any time. When it completes depends on the nature
of type T
. In many cases, when T
represents the entire body after being
read then it completes after the body has been read. If T
is a streaming
type such as InputStream
then it completes before the
body has been read, because the calling code uses it to consume the data.
Modifier and Type | Method | Description |
---|---|---|
static HttpResponse.BodyProcessor<byte[]> |
asByteArray() |
Returns a
BodyProcessor which stores the response body as a
byte array. |
static HttpResponse.BodyProcessor<Void> |
asByteArrayConsumer(Consumer<Optional<byte[]>> consumer) |
Returns a
BodyProcessor which provides the incoming body
data to the provided Consumer of Optional<byte[]> . |
static HttpResponse.BodyProcessor<Path> |
asFile(Path file) |
Returns a
BodyProcessor which stores the response body in a
file opened with the given name. |
static HttpResponse.BodyProcessor<Path> |
asFile(Path file,
OpenOption... openOptions) |
Returns a
BodyProcessor which stores the response body in a
file opened with the given options and name. |
static HttpResponse.BodyProcessor<String> |
asString(Charset charset) |
Returns a body processor which stores the response body as a
String converted using the given Charset . |
static <U> HttpResponse.BodyProcessor<U> |
discard(U value) |
Returns a response processor which discards the response body.
|
CompletionStage<T> |
getBody() |
Returns a
CompletionStage which when completed will return the
response body object. |
onComplete, onError, onNext, onSubscribe
CompletionStage<T> getBody()
CompletionStage
which when completed will return the
response body object.static HttpResponse.BodyProcessor<String> asString(Charset charset)
String
converted using the given Charset
.
The HttpResponse
using this processor is available after the
entire response has been read.
charset
- the character set to convert the String withstatic HttpResponse.BodyProcessor<byte[]> asByteArray()
BodyProcessor
which stores the response body as a
byte array.
The HttpResponse
using this processor is available after the
entire response has been read.
static HttpResponse.BodyProcessor<Path> asFile(Path file, OpenOption... openOptions)
BodyProcessor
which stores the response body in a
file opened with the given options and name. The file will be opened
with the given options using
FileChannel.open
just before the body is read. Any exception thrown will be returned
or thrown from HttpClient::send
or HttpClient::sendAsync
as appropriate.
The HttpResponse
using this processor is available after the
entire response has been read.
file
- the file to store the body inopenOptions
- the list of options to open the file withstatic HttpResponse.BodyProcessor<Void> asByteArrayConsumer(Consumer<Optional<byte[]>> consumer)
BodyProcessor
which provides the incoming body
data to the provided Consumer of Optional<byte[]>
. Each
call to Consumer.accept()
will contain a non empty Optional
, except for the final invocation after
all body data has been read, when the Optional
will be empty.
The HttpResponse
using this processor is available after the
entire response has been read.
consumer
- a Consumer of byte arraysstatic HttpResponse.BodyProcessor<Path> asFile(Path file)
BodyProcessor
which stores the response body in a
file opened with the given name. Has the same effect as calling
asFile
with the standard open options CREATE
and WRITE
The HttpResponse
using this processor is available after the
entire response has been read.
file
- the file to store the body instatic <U> HttpResponse.BodyProcessor<U> discard(U value)
HttpResponse.body()
.U
- The type of the response bodyvalue
- the value to return from HttpResponse.body()BodyProcessor
Submit a bug or feature
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 2015, 2016, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Ubuntu+0-9b149-1