Skip to content

Commit 0473e13

Browse files
authored
Avoid extra byte array copying when downloading to memory with AsyncResponseTransformer (#6348)
* Avoid extra byte array copying when downloading to memory with AsyncResponseTransformer * Add comments
1 parent 9316753 commit 0473e13

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Avoid extra byte array copying when downloading to memory with AsyncResponseTransformer"
6+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public final class ByteArrayAsyncResponseTransformer<ResponseT> implements
4747
@Override
4848
public CompletableFuture<ResponseBytes<ResponseT>> prepare() {
4949
cf = new CompletableFuture<>();
50-
return cf.thenApply(arr -> ResponseBytes.fromByteArray(response, arr));
50+
// Using fromByteArrayUnsafe() to avoid unnecessary extra copying of byte array. The data writing has completed and the
51+
// byte array will not be further modified so this is safe
52+
return cf.thenApply(arr -> ResponseBytes.fromByteArrayUnsafe(response, arr));
5153
}
5254

5355
@Override

0 commit comments

Comments
 (0)