Package software.amazon.awssdk.core.sync
Class RequestBody
java.lang.Object
software.amazon.awssdk.core.sync.RequestBody
Represents the body of an HTTP request. Must be provided for operations that have a streaming input.
Offers various convenience factory methods from common sources of data (File, String, byte[], etc).
-
Method Summary
Modifier and TypeMethodDescriptionlong
Deprecated.static RequestBody
empty()
Creates aRequestBody
with no content.static RequestBody
fromByteBuffer
(ByteBuffer byteBuffer) Creates aRequestBody
from aByteBuffer
.static RequestBody
fromBytes
(byte[] bytes) Creates aRequestBody
from a byte array.static RequestBody
fromContentProvider
(ContentStreamProvider provider, long contentLength, String mimeType) Creates aRequestBody
from the givenContentStreamProvider
.static RequestBody
fromContentProvider
(ContentStreamProvider provider, String mimeType) Creates aRequestBody
from the givenContentStreamProvider
.static RequestBody
Create aRequestBody
using the full contents of the specified file.static RequestBody
Create aRequestBody
using the full contents of the specified file.static RequestBody
fromInputStream
(InputStream inputStream, long contentLength) Creates aRequestBody
from an input stream.static RequestBody
fromRemainingByteBuffer
(ByteBuffer byteBuffer) Creates aRequestBody
from the remaining readable bytes from aByteBuffer
.static RequestBody
fromString
(String contents) Creates aRequestBody
from a string.static RequestBody
fromString
(String contents, Charset cs) Creates aRequestBody
from a string.
-
Method Details
-
contentStreamProvider
- Returns:
- RequestBody as an
InputStream
.
-
contentLength
Deprecated.- Returns:
- Content length of
RequestBody
.
-
optionalContentLength
- Returns:
- Optional object of content length of
RequestBody
.
-
contentType
- Returns:
- Content type of
RequestBody
.
-
fromFile
Create aRequestBody
using the full contents of the specified file.- Parameters:
path
- File to send to the service.- Returns:
- RequestBody instance.
-
fromFile
Create aRequestBody
using the full contents of the specified file.- Parameters:
file
- File to send to the service.- Returns:
- RequestBody instance.
-
fromInputStream
Creates aRequestBody
from an input stream. "Content-Length" must be provided so that the SDK does not have to make two passes of the data.The stream will not be closed by the SDK. It is up to to caller of this method to close the stream. The stream should not be read outside of the SDK (by another thread) as it will change the state of the
InputStream
and could tamper with the sending of the request.To support resetting via
ContentStreamProvider
, this usesInputStream.reset()
and uses a read limit of 128 KiB. If you need more control, usefromContentProvider(ContentStreamProvider, long, String)
orfromContentProvider(ContentStreamProvider, String)
.- Parameters:
inputStream
- Input stream to send to the service. The stream will not be closed by the SDK.contentLength
- Content length of data in input stream.- Returns:
- RequestBody instance.
-
fromString
Creates aRequestBody
from a string. String is sent using the provided encoding.- Parameters:
contents
- String to send to the service.cs
- TheCharset
to use.- Returns:
- RequestBody instance.
-
fromString
Creates aRequestBody
from a string. String is sent as UTF-8 encoded bytes.- Parameters:
contents
- String to send to the service.- Returns:
- RequestBody instance.
-
fromBytes
Creates aRequestBody
from a byte array. The contents of the byte array are copied so modifications to the original byte array are not reflected in theRequestBody
.- Parameters:
bytes
- The bytes to send to the service.- Returns:
- RequestBody instance.
-
fromByteBuffer
Creates aRequestBody
from aByteBuffer
. Buffer contents are copied so any modifications made to the originalByteBuffer
are not reflected in theRequestBody
.NOTE: This method always copies the entire contents of the buffer, ignoring 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:
- RequestBody instance.
-
fromRemainingByteBuffer
Creates aRequestBody
from the remaining readable bytes from aByteBuffer
. UnlikefromByteBuffer(ByteBuffer)
, this method respects the current read position of the buffer and reads only the remaining bytes. The buffer is copied before reading so no changes are made to original buffer.- Parameters:
byteBuffer
- ByteBuffer to send to the service.- Returns:
- RequestBody instance.
-
empty
Creates aRequestBody
with no content.- Returns:
- RequestBody instance.
-
fromContentProvider
public static RequestBody fromContentProvider(ContentStreamProvider provider, long contentLength, String mimeType) Creates aRequestBody
from the givenContentStreamProvider
.- Parameters:
provider
- The content provider.contentLength
- The content length.mimeType
- The MIME type of the content.- Returns:
- The created
RequestBody
.
-
fromContentProvider
Creates aRequestBody
from the givenContentStreamProvider
.- Parameters:
provider
- The content provider.mimeType
- The MIME type of the content.- Returns:
- The created
RequestBody
.
-
optionalContentLength()