IOUtils.closeQuietly seems to be deprecated in favor of TryWithResources, but how can it help me when need to close the resource in an async event listener, likte this when i'm uploading files with AmazonS3 and TransferManager?
final String key = rs.getString("id");
final InputStream data = rs.getBinaryStream("data");
final long length = rs.getLong("length");
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(length);
Upload upload = transferManager.upload(s3bucketName, key, data, objectMetadata);
upload.addProgressListener((com.amazonaws.event.ProgressListener) p -> {
switch (p.getEventType()) {
case TRANSFER_COMPLETED_EVENT:
case TRANSFER_FAILED_EVENT:
case TRANSFER_CANCELED_EVENT:
IOUtils.closeQuietly(data);
default:
break;
}
});
IO-504 is the Jira issue that deprecated it. As noted by a few comments on the issue from October 2020, the decision was made to un-deprecate it.
Per the release notes, it was un-deprecated in 2.9.0 (2021-05-22).