Flow.Publisher<ByteBuffer>public static interface HttpRequest.BodyProcessor extends Flow.Publisher<ByteBuffer>
ByteBuffers suitable for sending as request bodies.
BodyProcessors implement Flow.Publisher which means they
act as a publisher of byte buffers.
The HTTP client implementation subscribes to the processor in
order to receive the flow of outgoing data buffers. The normal semantics
of Flow.Subscriber and Flow.Publisher are implemented
by the library and expected from processor implementations.
Each outgoing request results in one Subscriber subscribing to the
Publisher in order to provide the sequence of ByteBuffers containing
the request body. ByteBuffers must be allocated by the processor,
and must not be accessed after being handed over to the library.
These subscriptions complete normally when the request is fully
sent, and can be canceled or terminated early through error. If a request
needs to be resent for any reason, then a new subscription is created
which is expected to generate the same data as before.
| Modifier and Type | Method | Description |
|---|---|---|
long |
contentLength() |
Returns the content length for this request body.
|
static HttpRequest.BodyProcessor |
fromByteArray(byte[] buf) |
Returns a request body processor whose body is the given byte array.
|
static HttpRequest.BodyProcessor |
fromByteArray(byte[] buf,
int offset,
int length) |
Returns a request body processor whose body is the content of the given byte
array of
length bytes starting from the specified
offset. |
static HttpRequest.BodyProcessor |
fromByteArrays(Iterable<byte[]> iter) |
A request body processor that takes data from an
Iterable of byte arrays. |
static HttpRequest.BodyProcessor |
fromFile(Path path) |
A request body processor that takes data from the contents of a File.
|
static HttpRequest.BodyProcessor |
fromInputStream(Supplier<? extends InputStream> streamSupplier) |
A request body processor that reads its data from an
InputStream. |
static HttpRequest.BodyProcessor |
fromString(String body) |
Returns a request body processor whose body is the given
String,
converted using the UTF_8
character set. |
static HttpRequest.BodyProcessor |
fromString(String s,
Charset charset) |
Returns a request body processor whose body is the given
String, converted
using the given character set. |
subscribestatic HttpRequest.BodyProcessor fromString(String body)
String,
converted using the UTF_8
character set.body - the String containing the bodystatic HttpRequest.BodyProcessor fromString(String s, Charset charset)
String, converted
using the given character set.s - the String containing the bodycharset - the character set to convert the string to bytesstatic HttpRequest.BodyProcessor fromInputStream(Supplier<? extends InputStream> streamSupplier)
InputStream.
A Supplier of InputStream is used in case the request needs
to be sent again as the content is not buffered. The Supplier may return
null on subsequent attempts in which case, the request fails.streamSupplier - a Supplier of open InputStreamsstatic HttpRequest.BodyProcessor fromByteArray(byte[] buf)
buf - the byte array containing the bodystatic HttpRequest.BodyProcessor fromByteArray(byte[] buf, int offset, int length)
length bytes starting from the specified
offset.buf - the byte array containing the bodyoffset - the offset of the first bytelength - the number of bytes to usestatic HttpRequest.BodyProcessor fromFile(Path path) throws FileNotFoundException
path - the path to the file containing the bodyFileNotFoundException - if path not foundstatic HttpRequest.BodyProcessor fromByteArrays(Iterable<byte[]> iter)
Iterable of byte arrays.
An Iterable is provided which supplies Iterator instances.
Each attempt to send the request results in one invocation of the
Iterableiter - an Iterable of byte arrayslong contentLength()
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, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b155-1