Skip to content

Commit 55383d3

Browse files
Enable zero-copy ByteBuffer publishing in AsyncRequestBody "unsafe" constructors (#4096)
1 parent 48a356c commit 55383d3

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed
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": "StephenFlavin",
5+
"description": "Enable zero-copy ByteBuffer publishing in AsyncRequestBody via \"unsafe\" constructors"
6+
}

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

-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import software.amazon.awssdk.annotations.SdkInternalApi;
2626
import software.amazon.awssdk.core.async.AsyncRequestBody;
2727
import software.amazon.awssdk.core.internal.util.Mimetype;
28-
import software.amazon.awssdk.utils.BinaryUtils;
2928
import software.amazon.awssdk.utils.Logger;
3029

3130
/**
@@ -96,11 +95,6 @@ public void request(long n) {
9695
do {
9796
ByteBuffer buffer = buffers[i];
9897

99-
// Pending discussions on https://github.com/aws/aws-sdk-java-v2/issues/3928
100-
if (buffer.isDirect()) {
101-
buffer = BinaryUtils.toNonDirectBuffer(buffer);
102-
}
103-
10498
s.onNext(buffer.asReadOnlyBuffer());
10599
remaining--;
106100
} while (remaining > 0 && (i = index.getAndIncrement()) < buffers.length);

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/async/ByteBuffersAsyncRequestBodyTest.java

-20
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,6 @@ public void canceledSubscriberDoesNotReturnNewResults() {
186186
assertTrue(subscriber.publishedResults.isEmpty());
187187
}
188188

189-
// Pending discussions on https://github.com/aws/aws-sdk-java-v2/issues/3928
190-
@Test
191-
public void directBuffersAreCoppiedToNonDirectBuffers() {
192-
byte[] bytes = "Hello World!".getBytes(StandardCharsets.UTF_8);
193-
ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.length)
194-
.put(bytes);
195-
buffer.flip();
196-
AsyncRequestBody requestBody = ByteBuffersAsyncRequestBody.of(buffer);
197-
198-
TestSubscriber subscriber = new TestSubscriber();
199-
requestBody.subscribe(subscriber);
200-
subscriber.request(1);
201-
202-
ByteBuffer publishedBuffer = subscriber.publishedResults.get(0);
203-
assertFalse(publishedBuffer.isDirect());
204-
byte[] publishedBytes = new byte[publishedBuffer.remaining()];
205-
publishedBuffer.get(publishedBytes);
206-
assertArrayEquals(bytes, publishedBytes);
207-
}
208-
209189
@Test
210190
public void staticOfByteBufferConstructorSetsLengthBasedOnBufferRemaining() {
211191
ByteBuffer bb1 = ByteBuffer.allocate(2);

0 commit comments

Comments
 (0)