Skip to content

Commit 3795cb9

Browse files
authored
Update java doc on ContentLength in requestBody for s3 uploads (#6051)
* Java doc related to contentLength updated * doc updated * doc updated * deleted unnecessary test
1 parent 76590d4 commit 3795cb9

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBody.java

+19
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ static AsyncRequestBody fromRemainingByteBuffersUnsafe(ByteBuffer... byteBuffers
356356
*
357357
* <p>An {@link ExecutorService} is required in order to perform the blocking data reads, to prevent blocking the
358358
* non-blocking event loop threads owned by the SDK.
359+
*
360+
* @param inputStream The input stream containing the data to be sent
361+
* @param contentLength The content length. If a content length smaller than the actual size of the object is set, the client
362+
* will truncate the stream to the specified content length and only send exactly the number of bytes
363+
* equal to the content length.
364+
* @param executor The executor
365+
*
366+
* @return An AsyncRequestBody instance for the input stream
367+
*
359368
*/
360369
static AsyncRequestBody fromInputStream(InputStream inputStream, Long contentLength, ExecutorService executor) {
361370
return fromInputStream(b -> b.inputStream(inputStream).contentLength(contentLength).executor(executor));
@@ -386,6 +395,7 @@ static AsyncRequestBody fromInputStream(Consumer<AsyncRequestBodyFromInputStream
386395
*
387396
* <p>By default, it will time out if streaming hasn't started within 10 seconds, and use application/octet-stream as
388397
* content type. You can configure it via {@link BlockingInputStreamAsyncRequestBody#builder()}
398+
*
389399
* <p><b>Example Usage</b>
390400
*
391401
* <p>
@@ -408,6 +418,10 @@ static AsyncRequestBody fromInputStream(Consumer<AsyncRequestBodyFromInputStream
408418
* // Wait for the service to respond.
409419
* PutObjectResponse response = responseFuture.join();
410420
* }
421+
* @param contentLength The content length. If a content length smaller than the actual size of the object is set, the client
422+
* will truncate the stream to the specified content length and only send exactly the number of bytes
423+
* equal to the content length.
424+
* @return The created {@code BlockingInputStreamAsyncRequestBody}.
411425
*/
412426
static BlockingInputStreamAsyncRequestBody forBlockingInputStream(Long contentLength) {
413427
return BlockingInputStreamAsyncRequestBody.builder()
@@ -447,6 +461,11 @@ static BlockingInputStreamAsyncRequestBody forBlockingInputStream(Long contentLe
447461
* PutObjectResponse response = responseFuture.join();
448462
* }
449463
* @see BlockingOutputStreamAsyncRequestBody
464+
*
465+
* @param contentLength The content length. If a content length smaller than the actual size of the object is set, the client
466+
* will truncate the stream to the specified content length and only send exactly the number of bytes
467+
* equal to the content length.
468+
* @return The created {@code BlockingOutputStreamAsyncRequestBody}.
450469
*/
451470
static BlockingOutputStreamAsyncRequestBody forBlockingOutputStream(Long contentLength) {
452471
return BlockingOutputStreamAsyncRequestBody.builder()

core/sdk-core/src/main/java/software/amazon/awssdk/core/sync/RequestBody.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ public static RequestBody fromFile(File file) {
128128
* To support resetting via {@link ContentStreamProvider}, this uses {@link InputStream#reset()} and uses a read limit of
129129
* 128 KiB. If you need more control, use {@link #fromContentProvider(ContentStreamProvider, long, String)} or
130130
* {@link #fromContentProvider(ContentStreamProvider, String)}.
131-
* <p>
132131
*
133132
* @param inputStream Input stream to send to the service. The stream will not be closed by the SDK.
134-
* @param contentLength Content length of data in input stream.
133+
* @param contentLength Content length of data in input stream. If a content length smaller than the actual size of the
134+
* object is set, the client will truncate the stream to the specified content length and only send
135+
* exactly the number of bytes equal to the content length.
135136
* @return RequestBody instance.
136137
*/
137138
public static RequestBody fromInputStream(InputStream inputStream, long contentLength) {
@@ -220,9 +221,14 @@ public static RequestBody empty() {
220221
* S3's documentation for
221222
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/s3_example_s3_Scenario_UploadStream_section.html">alternative
222223
* methods</a>.
224+
* <p>
225+
* If a content length smaller than the actual size of the object is set, the client will truncate the stream to the
226+
* specified content length and only send exactly the number of bytes equal to the content length.
223227
*
224228
* @param provider The content provider.
225-
* @param contentLength The content length.
229+
* @param contentLength The content length. If a content length smaller than the actual size of the object is set, the client
230+
* will truncate the stream to the specified content length and only send exactly the number of bytes
231+
* equal to the content length.
226232
* @param mimeType The MIME type of the content.
227233
*
228234
* @return The created {@code RequestBody}.

0 commit comments

Comments
 (0)