public interface AsyncRequestBody extends SdkPublisher<ByteBuffer>
Publisher
of data (specifically ByteBuffer
chunks) and the HTTP client is the Subscriber
of the data (i.e. to write that data on the wire).
Publisher.subscribe(Subscriber)
should be implemented to tie this publisher to a subscriber. Ideally each call to subscribe
should reproduce the content (i.e if you are reading from a file each subscribe call should produce a Subscription
that reads the file fully). This allows for automatic retries to be performed in the SDK. If
the content is not reproducible, an exception may be thrown from any subsequent Publisher.subscribe(Subscriber)
calls.
It is important to only send the number of chunks that the subscriber requests to avoid out of memory situations.
The subscriber does it's own buffering so it's usually not needed to buffer in the publisher. Additional permits
for chunks will be notified via the Subscription.request(long)
method.
FileAsyncRequestBody
,
ByteArrayAsyncRequestBody
Modifier and Type | Method and Description |
---|---|
Optional<Long> |
contentLength() |
static AsyncRequestBody |
empty()
Creates a
AsyncRequestBody with no content. |
static AsyncRequestBody |
fromByteBuffer(ByteBuffer byteBuffer)
Creates a
AsyncRequestBody from a ByteBuffer . |
static AsyncRequestBody |
fromBytes(byte[] bytes)
Creates a
AsyncRequestBody from a byte array. |
static AsyncRequestBody |
fromFile(File file)
Creates an
AsyncRequestBody that produces data from the contents of a file. |
static AsyncRequestBody |
fromFile(Path path)
Creates an
AsyncRequestBody that produces data from the contents of a file. |
static AsyncRequestBody |
fromPublisher(org.reactivestreams.Publisher<ByteBuffer> publisher)
Creates an
AsyncRequestBody the produces data from the input ByteBuffer publisher. |
static AsyncRequestBody |
fromString(String string)
Creates an
AsyncRequestBody that uses a single string as data with UTF_8 encoding. |
static AsyncRequestBody |
fromString(String string,
Charset cs)
Creates an
AsyncRequestBody that uses a single string as data. |
adapt, buffer, filter, filter, flatMapIterable, limit, map, subscribe
Optional<Long> contentLength()
static AsyncRequestBody fromPublisher(org.reactivestreams.Publisher<ByteBuffer> publisher)
AsyncRequestBody
the produces data from the input ByteBuffer publisher.
The data is delivered when the publisher publishes the data.publisher
- Publisher of source dataAsyncRequestBody
that produces data send by the publisherstatic AsyncRequestBody fromFile(Path path)
AsyncRequestBody
that produces data from the contents of a file. See
FileAsyncRequestBody.builder()
to create a customized body implementation.path
- Path to file to read from.AsyncRequestBody
that reads data from the specified file.FileAsyncRequestBody
static AsyncRequestBody fromFile(File file)
AsyncRequestBody
that produces data from the contents of a file. See
FileAsyncRequestBody.builder()
to create a customized body implementation.file
- The file to read from.AsyncRequestBody
that reads data from the specified file.FileAsyncRequestBody
static AsyncRequestBody fromString(String string, Charset cs)
AsyncRequestBody
that uses a single string as data.string
- The string to provide.cs
- The Charset
to use.AsyncRequestBody
that uses the specified string.ByteArrayAsyncRequestBody
static AsyncRequestBody fromString(String string)
AsyncRequestBody
that uses a single string as data with UTF_8 encoding.string
- The string to send.AsyncRequestBody
that uses the specified string.fromString(String, Charset)
static AsyncRequestBody fromBytes(byte[] bytes)
AsyncRequestBody
from a byte array. The contents of the byte array are copied so modifications to the
original byte array are not reflected in the AsyncRequestBody
.bytes
- The bytes to send to the service.static AsyncRequestBody fromByteBuffer(ByteBuffer byteBuffer)
AsyncRequestBody
from a ByteBuffer
. Buffer contents are copied so any modifications
made to the original ByteBuffer
are not reflected in the AsyncRequestBody
.byteBuffer
- ByteBuffer to send to the service.static AsyncRequestBody empty()
AsyncRequestBody
with no content.Copyright © 2018. All rights reserved.