Search in sources :

Example 1 with ResponsePublisher

use of software.amazon.awssdk.core.async.ResponsePublisher in project aws-sdk-java-v2 by aws.

the class S3TransferManagerDownloadIntegrationTest method download_toPublisher.

@Test
public void download_toPublisher() throws Exception {
    Download<ResponsePublisher<GetObjectResponse>> download = tm.download(DownloadRequest.builder().getObjectRequest(b -> b.bucket(BUCKET).key(KEY)).responseTransformer(AsyncResponseTransformer.toPublisher()).overrideConfiguration(b -> b.addListener(LoggingTransferListener.create())).build());
    CompletedDownload<ResponsePublisher<GetObjectResponse>> completedDownload = download.completionFuture().join();
    ResponsePublisher<GetObjectResponse> responsePublisher = completedDownload.result();
    ByteBuffer buf = ByteBuffer.allocate(Math.toIntExact(responsePublisher.response().contentLength()));
    CompletableFuture<Void> drainPublisherFuture = responsePublisher.subscribe(buf::put);
    drainPublisherFuture.join();
    assertThat(Md5Utils.md5AsBase64(buf.array())).isEqualTo(Md5Utils.md5AsBase64(file));
}
Also used : GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ResponsePublisher(software.amazon.awssdk.core.async.ResponsePublisher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 ResponsePublisher (software.amazon.awssdk.core.async.ResponsePublisher)1 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)1