Trying to find how to output a clean count of 0 - 100% while downloading a file from amazon. There are plenty of examples of how to do this for uploading but they don't seem to directly translate to downloads.
At the moment I'm doing the following
TransferManager transferManager = new TransferManager(s3Client); Download download = transferManager.download(s3Request, downloadedFile); while (!download.isDone()) { LOGGER.info("Downloaded >> " + download.getProgress().getPercentTransferred()); }
Which does work, but it spams the console with the same value many many times (assume as it's threaded).
I know I can also do something like:
ProgressListener listener = progressEvent -> LOGGER.info("Bytes transfer >> " + progressEvent.getBytesTransferred()); GetObjectRequest s3Request = new GetObjectRequest("swordfish-database", snapshot.getKey()); TransferManager transferManager = new TransferManager(s3Client); Download download = transferManager.download(s3Request, downloadedFile); download.addProgressListener(listener); download.waitForCompletion();
Which also works but, I loose the ease of using download.getProgress().getPercentTransferred()
. Is this the more proper way of doing this?
Ultimately I want to be getting an int to use for a progress bar.