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() |
default String |
contentType() |
static AsyncRequestBody |
empty()
Creates a
AsyncRequestBody with no content. |
static BlockingInputStreamAsyncRequestBody |
forBlockingInputStream(Long contentLength)
Creates a
BlockingInputStreamAsyncRequestBody to use for writing an input stream to the downstream service. |
static BlockingOutputStreamAsyncRequestBody |
forBlockingOutputStream(Long contentLength)
Creates a
BlockingOutputStreamAsyncRequestBody to use for writing to the downstream service as if it's an output
stream. |
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 |
fromInputStream(InputStream inputStream,
Long contentLength,
ExecutorService executor)
Creates a
AsyncRequestBody from a InputStream. |
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, doAfterOnCancel, doAfterOnComplete, doAfterOnError, filter, filter, flatMapIterable, limit, map, subscribeOptional<Long> contentLength()
default String contentType()
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.FileAsyncRequestBodystatic 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.FileAsyncRequestBodystatic 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.ByteArrayAsyncRequestBodystatic 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 fromInputStream(InputStream inputStream, Long contentLength, ExecutorService executor)
AsyncRequestBody from a InputStream.
An ExecutorService is required in order to perform the blocking data reads, to prevent blocking the
non-blocking event loop threads owned by the SDK.
static BlockingInputStreamAsyncRequestBody forBlockingInputStream(Long contentLength)
BlockingInputStreamAsyncRequestBody to use for writing an input stream to the downstream service.
Example Usage
static BlockingOutputStreamAsyncRequestBody forBlockingOutputStream(Long contentLength)
BlockingOutputStreamAsyncRequestBody to use for writing to the downstream service as if it's an output
stream. Retries are not supported for this request body.
The caller is responsible for calling OutputStream.close() on the #outputStream() when writing is
complete.
Example Usage
static AsyncRequestBody empty()
AsyncRequestBody with no content.Copyright © 2023. All rights reserved.