Skip to content

Commit eea77c1

Browse files
authored
fix: convert to a blocking input stream instead of going through a by… (#96)
* fix: convert to a blocking input stream instead of going through a byte array
1 parent ba78c2c commit eea77c1

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
55
import software.amazon.awssdk.awscore.exception.AwsServiceException;
6-
import software.amazon.awssdk.core.ResponseBytes;
6+
import software.amazon.awssdk.core.ResponseInputStream;
77
import software.amazon.awssdk.core.async.AsyncRequestBody;
88
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
99
import software.amazon.awssdk.core.exception.SdkClientException;
@@ -139,8 +139,8 @@ public <T> T getObject(GetObjectRequest getObjectRequest,
139139
.build();
140140

141141
try {
142-
ResponseBytes<GetObjectResponse> joinFutureGet = pipeline.getObject(getObjectRequest, AsyncResponseTransformer.toBytes()).join();
143-
return responseTransformer.transform(joinFutureGet.response(), AbortableInputStream.create(joinFutureGet.asInputStream()));
142+
ResponseInputStream<GetObjectResponse> joinFutureGet = pipeline.getObject(getObjectRequest, AsyncResponseTransformer.toBlockingInputStream()).join();
143+
return responseTransformer.transform(joinFutureGet.response(), AbortableInputStream.create(joinFutureGet));
144144
} catch (CompletionException e) {
145145
throw new S3EncryptionClientException(e.getCause().getMessage(), e.getCause());
146146
} catch (Exception e) {

src/test/java/software/amazon/encryption/s3/S3EncryptionClientStreamTest.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -155,42 +155,6 @@ public void ordinaryInputStreamV3Decrypt() throws IOException {
155155
v3Client.close();
156156
}
157157

158-
@Test
159-
public void markResetInputStreamV3DecryptGcm() throws IOException {
160-
final String objectKey = appendTestSuffix("markResetInputStreamV3DecryptGcm");
161-
162-
// V3 Client
163-
S3Client v3Client = S3EncryptionClient.builder()
164-
.aesKey(AES_KEY)
165-
.build();
166-
167-
final int inputLength = DEFAULT_TEST_STREAM_LENGTH;
168-
// Create a second stream of zeros because reset is not supported
169-
// and reading into the byte string will consume the stream.
170-
final InputStream inputStream = new BoundedZerosInputStream(inputLength);
171-
final InputStream inputStreamForString = new BoundedZerosInputStream(inputLength);
172-
final String inputStreamAsUtf8String = IoUtils.toUtf8String(inputStreamForString);
173-
174-
v3Client.putObject(PutObjectRequest.builder()
175-
.bucket(BUCKET)
176-
.key(objectKey)
177-
.build(), RequestBody.fromInputStream(inputStream, inputLength));
178-
inputStream.close();
179-
180-
final ResponseInputStream<GetObjectResponse> responseInputStream = v3Client.getObject(builder -> builder
181-
.bucket(BUCKET)
182-
.key(objectKey)
183-
.build());
184-
final String actualObject = new String(BoundedStreamBufferer.toByteArrayWithMarkReset(responseInputStream, inputLength / 8),
185-
StandardCharsets.UTF_8);
186-
187-
assertEquals(inputStreamAsUtf8String, actualObject);
188-
189-
// Cleanup
190-
deleteObject(BUCKET, objectKey, v3Client);
191-
v3Client.close();
192-
}
193-
194158
@Test
195159
public void ordinaryInputStreamV3DecryptCbc() throws IOException {
196160
final String objectKey = appendTestSuffix("markResetInputStreamV3DecryptCbc");

0 commit comments

Comments
 (0)