use of com.amazonaws.services.s3.transfer.TransferManager in project carina by qaprosoft.
the class AmazonS3Manager method download.
/**
* Method to download file from s3 to local file system
*
* @param bucketName AWS S3 bucket name
* @param key (example: android/apkFolder/ApkName.apk)
* @param file (local file name)
* @param pollingInterval (polling interval in sec for S3 download status determination)
*/
public void download(final String bucketName, final String key, final File file, long pollingInterval) {
LOGGER.info("App will be downloaded from s3.");
LOGGER.info(String.format("[Bucket name: %s] [Key: %s] [File: %s]", bucketName, key, file.getAbsolutePath()));
DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
TransferManager tx = new TransferManager(credentialProviderChain.getCredentials());
Download appDownload = tx.download(bucketName, key, file);
try {
LOGGER.info("Transfer: " + appDownload.getDescription());
LOGGER.info(" State: " + appDownload.getState());
LOGGER.info(" Progress: ");
// You can poll your transfer's status to check its progress
while (!appDownload.isDone()) {
LOGGER.info(" transferred: " + (int) (appDownload.getProgress().getPercentTransferred() + 0.5) + "%");
CommonUtils.pause(pollingInterval);
}
LOGGER.info(" State: " + appDownload.getState());
// appDownload.waitForCompletion();
} catch (AmazonClientException e) {
throw new RuntimeException("File wasn't downloaded from s3. See log: ".concat(e.getMessage()));
}
// tx.shutdownNow();
}
Aggregations