Interface AsyncRequestBody
-
- All Superinterfaces:
org.reactivestreams.Publisher<ByteBuffer>
,SdkPublisher<ByteBuffer>
- All Known Implementing Classes:
AsyncRequestBodyListener.NotifyingAsyncRequestBody
,BlockingInputStreamAsyncRequestBody
,BlockingOutputStreamAsyncRequestBody
,ByteBuffersAsyncRequestBody
,ChecksumCalculatingAsyncRequestBody
,CompressionAsyncRequestBody
,FileAsyncRequestBody
,InputStreamWithExecutorAsyncRequestBody
public interface AsyncRequestBody extends SdkPublisher<ByteBuffer>
Interface to allow non-blocking streaming of request content. This follows the reactive streams pattern where this interface is thePublisher
of data (specificallyByteBuffer
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 aSubscription
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 subsequentPublisher.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.- See Also:
FileAsyncRequestBody
,ByteBuffersAsyncRequestBody
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<Long>
contentLength()
default String
contentType()
static AsyncRequestBody
empty()
Creates anAsyncRequestBody
with no content.static BlockingInputStreamAsyncRequestBody
forBlockingInputStream(Long contentLength)
Creates aBlockingInputStreamAsyncRequestBody
to use for writing an input stream to the downstream service.static BlockingOutputStreamAsyncRequestBody
forBlockingOutputStream(Long contentLength)
Creates aBlockingOutputStreamAsyncRequestBody
to use for writing to the downstream service as if it's an output stream.static AsyncRequestBody
fromByteBuffer(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from aByteBuffer
.static AsyncRequestBody
fromByteBuffers(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array.static AsyncRequestBody
fromByteBuffersUnsafe(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array without copying the contents of eachByteBuffer
.static AsyncRequestBody
fromByteBufferUnsafe(ByteBuffer byteBuffer)
static AsyncRequestBody
fromBytes(byte[] bytes)
Creates anAsyncRequestBody
from a byte array.static AsyncRequestBody
fromBytesUnsafe(byte[] bytes)
Creates anAsyncRequestBody
from a byte array without copying the contents of the byte array.static AsyncRequestBody
fromFile(File file)
Creates anAsyncRequestBody
that produces data from the contents of a file.static AsyncRequestBody
fromFile(Path path)
Creates anAsyncRequestBody
that produces data from the contents of a file.static AsyncRequestBody
fromFile(Consumer<FileRequestBodyConfiguration.Builder> configuration)
Creates anAsyncRequestBody
that produces data from the contents of a file.static AsyncRequestBody
fromFile(FileRequestBodyConfiguration configuration)
Creates anAsyncRequestBody
that produces data from the contents of a file.static AsyncRequestBody
fromInputStream(InputStream inputStream, Long contentLength, ExecutorService executor)
Creates anAsyncRequestBody
from anInputStream
.static AsyncRequestBody
fromInputStream(Consumer<AsyncRequestBodyFromInputStreamConfiguration.Builder> configuration)
This is a convenience method that passes an instance of theAsyncRequestBodyFromInputStreamConfiguration
builder, avoiding the need to create one manually viaAsyncRequestBodyFromInputStreamConfiguration.builder()
.static AsyncRequestBody
fromInputStream(AsyncRequestBodyFromInputStreamConfiguration configuration)
Creates anAsyncRequestBody
from anInputStream
with the providedAsyncRequestBodySplitConfiguration
.static AsyncRequestBody
fromPublisher(org.reactivestreams.Publisher<ByteBuffer> publisher)
Creates anAsyncRequestBody
the produces data from the input ByteBuffer publisher.static AsyncRequestBody
fromRemainingByteBuffer(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from the remaining readable bytes from aByteBuffer
.static AsyncRequestBody
fromRemainingByteBuffers(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array.static AsyncRequestBody
fromRemainingByteBuffersUnsafe(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array without copying the contents of eachByteBuffer
.static AsyncRequestBody
fromRemainingByteBufferUnsafe(ByteBuffer byteBuffer)
static AsyncRequestBody
fromString(String string)
Creates anAsyncRequestBody
that uses a single string as data with UTF_8 encoding.static AsyncRequestBody
fromString(String string, Charset cs)
Creates anAsyncRequestBody
that uses a single string as data.default SdkPublisher<AsyncRequestBody>
split(Consumer<AsyncRequestBodySplitConfiguration.Builder> splitConfiguration)
This is a convenience method that passes an instance of theAsyncRequestBodySplitConfiguration
builder, avoiding the need to create one manually viaAsyncRequestBodySplitConfiguration.builder()
.default SdkPublisher<AsyncRequestBody>
split(AsyncRequestBodySplitConfiguration splitConfiguration)
Converts thisAsyncRequestBody
to a publisher ofAsyncRequestBody
s, each of which publishes a specific portion of the original data, based on the providedAsyncRequestBodySplitConfiguration
.-
Methods inherited from interface software.amazon.awssdk.core.async.SdkPublisher
addTrailingData, buffer, doAfterOnCancel, doAfterOnComplete, doAfterOnError, filter, filter, flatMapIterable, limit, map, subscribe
-
-
-
-
Method Detail
-
contentLength
Optional<Long> contentLength()
- Returns:
- The content length of the data being produced.
-
contentType
default String contentType()
- Returns:
- The content type of the data being produced.
-
fromPublisher
static AsyncRequestBody fromPublisher(org.reactivestreams.Publisher<ByteBuffer> publisher)
Creates anAsyncRequestBody
the produces data from the input ByteBuffer publisher. The data is delivered when the publisher publishes the data.- Parameters:
publisher
- Publisher of source data- Returns:
- Implementation of
AsyncRequestBody
that produces data send by the publisher
-
fromFile
static AsyncRequestBody fromFile(Path path)
Creates anAsyncRequestBody
that produces data from the contents of a file. SeeFileAsyncRequestBody.builder()
to create a customized body implementation.- Parameters:
path
- Path to file to read from.- Returns:
- Implementation of
AsyncRequestBody
that reads data from the specified file. - See Also:
FileAsyncRequestBody
-
fromFile
static AsyncRequestBody fromFile(File file)
Creates anAsyncRequestBody
that produces data from the contents of a file. SeefromFile(FileRequestBodyConfiguration)
to create a customized body implementation.- Parameters:
file
- The file to read from.- Returns:
- Implementation of
AsyncRequestBody
that reads data from the specified file.
-
fromFile
static AsyncRequestBody fromFile(FileRequestBodyConfiguration configuration)
Creates anAsyncRequestBody
that produces data from the contents of a file.- Parameters:
configuration
- configuration for how the SDK should read the file- Returns:
- Implementation of
AsyncRequestBody
that reads data from the specified file.
-
fromFile
static AsyncRequestBody fromFile(Consumer<FileRequestBodyConfiguration.Builder> configuration)
Creates anAsyncRequestBody
that produces data from the contents of a file.This is a convenience method that creates an instance of the
FileRequestBodyConfiguration
builder, avoiding the need to create one manually viaFileRequestBodyConfiguration.builder()
.- Parameters:
configuration
- configuration for how the SDK should read the file- Returns:
- Implementation of
AsyncRequestBody
that reads data from the specified file.
-
fromString
static AsyncRequestBody fromString(String string, Charset cs)
Creates anAsyncRequestBody
that uses a single string as data.- Parameters:
string
- The string to provide.cs
- TheCharset
to use.- Returns:
- Implementation of
AsyncRequestBody
that uses the specified string. - See Also:
ByteBuffersAsyncRequestBody
-
fromString
static AsyncRequestBody fromString(String string)
Creates anAsyncRequestBody
that uses a single string as data with UTF_8 encoding.- Parameters:
string
- The string to send.- Returns:
- Implementation of
AsyncRequestBody
that uses the specified string. - See Also:
fromString(String, Charset)
-
fromBytes
static AsyncRequestBody fromBytes(byte[] bytes)
Creates anAsyncRequestBody
from a byte array. This will copy the contents of the byte array to prevent modifications to the provided byte array from being reflected in theAsyncRequestBody
.- Parameters:
bytes
- The bytes to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromBytesUnsafe
static AsyncRequestBody fromBytesUnsafe(byte[] bytes)
Creates anAsyncRequestBody
from a byte array without copying the contents of the byte array. This introduces concurrency risks, allowing: (1) the caller to modify the byte array stored in thisAsyncRequestBody
implementation AND (2) any users offromBytesUnsafe(byte[])
to modify the byte array passed into thisAsyncRequestBody
implementation.As the method name implies, this is unsafe. Use
fromBytes(byte[])
unless you're sure you know the risks.- Parameters:
bytes
- The bytes to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromByteBuffer
static AsyncRequestBody fromByteBuffer(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from aByteBuffer
. This will copy the contents of theByteBuffer
to prevent modifications to the providedByteBuffer
from being reflected in theAsyncRequestBody
.NOTE: This method ignores the current read position. Use
fromRemainingByteBuffer(ByteBuffer)
if you need it to copy only the remaining readable bytes.- Parameters:
byteBuffer
- ByteBuffer to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromRemainingByteBuffer
static AsyncRequestBody fromRemainingByteBuffer(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from the remaining readable bytes from aByteBuffer
. This will copy the remaining contents of theByteBuffer
to prevent modifications to the providedByteBuffer
from being reflected in theAsyncRequestBody
.Unlike
fromByteBuffer(ByteBuffer)
, this method respects the current read position of the buffer and reads only the remaining bytes.- Parameters:
byteBuffer
- ByteBuffer to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromByteBufferUnsafe
static AsyncRequestBody fromByteBufferUnsafe(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from aByteBuffer
without copying the contents of theByteBuffer
. This introduces concurrency risks, allowing the caller to modify theByteBuffer
stored in thisAsyncRequestBody
implementation.NOTE: This method ignores the current read position. Use
fromRemainingByteBufferUnsafe(ByteBuffer)
if you need it to copy only the remaining readable bytes.As the method name implies, this is unsafe. Use
fromByteBuffer(ByteBuffer)
} unless you're sure you know the risks.- Parameters:
byteBuffer
- ByteBuffer to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromRemainingByteBufferUnsafe
static AsyncRequestBody fromRemainingByteBufferUnsafe(ByteBuffer byteBuffer)
Creates anAsyncRequestBody
from aByteBuffer
without copying the contents of theByteBuffer
. This introduces concurrency risks, allowing the caller to modify theByteBuffer
stored in thisAsyncRequestBody
implementation.Unlike
fromByteBufferUnsafe(ByteBuffer)
, this method respects the current read position of the buffer and reads only the remaining bytes.As the method name implies, this is unsafe. Use
fromByteBuffer(ByteBuffer)
} unless you're sure you know the risks.- Parameters:
byteBuffer
- ByteBuffer to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromByteBuffers
static AsyncRequestBody fromByteBuffers(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array. This will copy the contents of eachByteBuffer
to prevent modifications to any providedByteBuffer
from being reflected in theAsyncRequestBody
.NOTE: This method ignores the current read position of each
ByteBuffer
. UsefromRemainingByteBuffers(ByteBuffer...)
if you need it to copy only the remaining readable bytes.- Parameters:
byteBuffers
- ByteBuffer array to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromRemainingByteBuffers
static AsyncRequestBody fromRemainingByteBuffers(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array. This will copy the remaining contents of eachByteBuffer
to prevent modifications to any providedByteBuffer
from being reflected in theAsyncRequestBody
.Unlike
fromByteBufferUnsafe(ByteBuffer)
, this method respects the current read position of each buffer and reads only the remaining bytes.- Parameters:
byteBuffers
- ByteBuffer array to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromByteBuffersUnsafe
static AsyncRequestBody fromByteBuffersUnsafe(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array without copying the contents of eachByteBuffer
. This introduces concurrency risks, allowing the caller to modify anyByteBuffer
stored in thisAsyncRequestBody
implementation.NOTE: This method ignores the current read position of each
ByteBuffer
. UsefromRemainingByteBuffers(ByteBuffer...)
if you need it to copy only the remaining readable bytes.As the method name implies, this is unsafe. Use
fromByteBuffers(ByteBuffer...)
unless you're sure you know the risks.- Parameters:
byteBuffers
- ByteBuffer array to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromRemainingByteBuffersUnsafe
static AsyncRequestBody fromRemainingByteBuffersUnsafe(ByteBuffer... byteBuffers)
Creates anAsyncRequestBody
from aByteBuffer
array without copying the contents of eachByteBuffer
. This introduces concurrency risks, allowing the caller to modify anyByteBuffer
stored in thisAsyncRequestBody
implementation.Unlike
fromByteBuffersUnsafe(ByteBuffer...)
, this method respects the current read position of each buffer and reads only the remaining bytes.As the method name implies, this is unsafe. Use
fromByteBuffers(ByteBuffer...)
unless you're sure you know the risks.- Parameters:
byteBuffers
- ByteBuffer array to send to the service.- Returns:
- AsyncRequestBody instance.
-
fromInputStream
static AsyncRequestBody fromInputStream(InputStream inputStream, Long contentLength, ExecutorService executor)
Creates anAsyncRequestBody
from anInputStream
.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.
-
fromInputStream
static AsyncRequestBody fromInputStream(AsyncRequestBodyFromInputStreamConfiguration configuration)
Creates anAsyncRequestBody
from anInputStream
with the providedAsyncRequestBodySplitConfiguration
.
-
fromInputStream
static AsyncRequestBody fromInputStream(Consumer<AsyncRequestBodyFromInputStreamConfiguration.Builder> configuration)
This is a convenience method that passes an instance of theAsyncRequestBodyFromInputStreamConfiguration
builder, avoiding the need to create one manually viaAsyncRequestBodyFromInputStreamConfiguration.builder()
.
-
forBlockingInputStream
static BlockingInputStreamAsyncRequestBody forBlockingInputStream(Long contentLength)
Creates aBlockingInputStreamAsyncRequestBody
to use for writing an input stream to the downstream service.By default, it will time out if streaming hasn't started within 10 seconds, and use application/octet-stream as content type. You can configure it via
BlockingInputStreamAsyncRequestBody.builder()
Example Usage
-
forBlockingOutputStream
static BlockingOutputStreamAsyncRequestBody forBlockingOutputStream(Long contentLength)
Creates aBlockingOutputStreamAsyncRequestBody
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 theBlockingOutputStreamAsyncRequestBody.outputStream()
when writing is complete.By default, it will time out if streaming hasn't started within 10 seconds, and you can configure the timeout via
BlockingOutputStreamAsyncRequestBody.builder()
Example Usage
- See Also:
BlockingOutputStreamAsyncRequestBody
-
empty
static AsyncRequestBody empty()
Creates anAsyncRequestBody
with no content.- Returns:
- AsyncRequestBody instance.
-
split
default SdkPublisher<AsyncRequestBody> split(AsyncRequestBodySplitConfiguration splitConfiguration)
Converts thisAsyncRequestBody
to a publisher ofAsyncRequestBody
s, each of which publishes a specific portion of the original data, based on the providedAsyncRequestBodySplitConfiguration
. The default chunk size is 2MB and the default buffer size is 8MB.By default, if content length of this
AsyncRequestBody
is present, each dividedAsyncRequestBody
is delivered to the subscriber right after it's initialized. On the other hand, if content length is null, it is sent after the entire content for that chunk is buffered. In this case, the configuredmaxMemoryUsageInBytes
must be larger than or equal tochunkSizeInBytes
. Note that this behavior may be different if a specific implementation of this interface overrides this method.- See Also:
AsyncRequestBodySplitConfiguration
-
split
default SdkPublisher<AsyncRequestBody> split(Consumer<AsyncRequestBodySplitConfiguration.Builder> splitConfiguration)
This is a convenience method that passes an instance of theAsyncRequestBodySplitConfiguration
builder, avoiding the need to create one manually viaAsyncRequestBodySplitConfiguration.builder()
.
-
-