1

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;
    }
});
wutzebaer
  • 14,365
  • 19
  • 99
  • 170
  • Why are you attaching a progress listener used only as a kind of a callback just to check whether the transfer completed or not? Granted `upload` is non-block operation so are you after multiple upload without caring for the result? If this is the case then we're taking about something different. Otherwise if your code handles only a single file upload for each call to it and you do care about the outcome, then what you're doing is incorrect. – akortex Apr 22 '20 at 22:23

1 Answers1

6

This is the Jira issue that deprecated it. Based on the last few comments, from October 2020, looks like it is being un-deprecated.

UPDATE: Per the Release Notes, it was un-deprecated in 2.9.0 (2021-05-22).

Jamie Bisotti
  • 2,605
  • 19
  • 23