This example code in the original blog post is not correct, see the same code in github repo:
public static void main(String[] args) {
final S3AsyncClient client = S3AsyncClient.create();
final CompletableFuture<GetObjectResponse> future = client.getObject(
GetObjectRequest.builder()
.bucket(BUCKET)
.key("somedocument")
.build(),
AsyncResponseHandler.toFile(Paths.get("myfile.out")));
future.whenComplete((resp, err) -> {
try {
if (resp != null) {
System.out.println(resp);
} else {
err.printStackTrace();
}
} finally {
FunctionalUtils.invokeSafely(client::close);
}
});
}
Notice that it is CompletableFuture<GetObjectResponse> instead of CompletableFuture<Void>.
Secondly, when this code is executed, it is returned immediately, without waiting for the task to finish.
This example code in the original blog post is not correct, see the same code in github repo:
Notice that it is
CompletableFuture<GetObjectResponse>instead ofCompletableFuture<Void>.Secondly, when this code is executed, it is returned immediately, without waiting for the task to finish.