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));
}
Aggregations