本文整理匯總了Java中com.amazonaws.services.s3.transfer.TransferManager.download方法的典型用法代碼示例。如果您正苦於以下問題:Java TransferManager.download方法的具體用法?Java TransferManager.download怎麽用?Java TransferManager.download使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.transfer.TransferManager
的用法示例。
在下文中一共展示了TransferManager.download方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retrieve
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
@Override
public String retrieve(String file) throws Exception {
LogUtils.debug(LOG_TAG, "Downloading file: " + file);
TransferManager tm = new TransferManager(new DefaultAWSCredentialsProviderChain());
// TransferManager processes all transfers asynchronously,
// so this call will return immediately.
File downloadedFile = new File(Constants.MCSFS_WORKING_DIR + Constants.S3_WORKING_DIR + file + System.currentTimeMillis());
downloadedFile.getParentFile().mkdirs();
downloadedFile.createNewFile();
Download download = tm.download(bucketName, file, downloadedFile);
download.waitForCompletion();
LogUtils.debug(LOG_TAG, "Successfully downloaded file from bucket.\nName: " + file + "\nBucket name: " +
bucketName);
tm.shutdownNow();
return downloadedFile.getAbsolutePath();
}
示例2: downloadFile
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
private void downloadFile(TransferManager tx,
String bucketName,
String sourcePrefixKey,
String destinationFile) throws Exception{
try {
final File snapshotFile = new File(destinationFile);
// Only create parent directory once, if it doesn't exist.
final File parentDir = new File(snapshotFile.getParent());
if (!parentDir.isDirectory()) {
final boolean parentDirCreated = parentDir.mkdirs();
if (!parentDirCreated) {
LOGGER.error(
"Error creating parent directory for file: {}. Skipping to next",
destinationFile);
return;
}
}
snapshotFile.createNewFile();
final Download download = tx.download(bucketName, sourcePrefixKey, snapshotFile);
download.waitForCompletion();
} catch (Exception e) {
LOGGER.error("Error downloading the file {} : {}", destinationFile, e);
throw new Exception(e);
}
}
示例3: downloadFile
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
public static void downloadFile(String bucket_name, String key_name,
String file_path, boolean pause)
{
System.out.println("Downloading to file: " + file_path +
(pause ? " (pause)" : ""));
File f = new File(file_path);
TransferManager xfer_mgr = new TransferManager();
try {
Download xfer = xfer_mgr.download(bucket_name, key_name, f);
// loop with Transfer.isDone()
XferMgrProgress.showTransferProgress(xfer);
// or block with Transfer.waitForCompletion()
XferMgrProgress.waitForCompletion(xfer);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
xfer_mgr.shutdownNow();
}
示例4: download
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
/**
* 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();
}
示例5: main
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// create the AWS S3 Client
AmazonS3 s3 = AWSS3Factory.getS3Client();
// retrieve the key value from user
System.out.println( "Enter the object key:" );
String key = new BufferedReader( new InputStreamReader( System.in ) ).readLine();
// print start time
Date start_date = new Date();
System.out.println(start_date.toString());
// file will be placed in temp dir with .tmp extension
File file = File.createTempFile("read-large-object-tm", null);
TransferManager tm = TransferManagerBuilder.standard()
.withS3Client(s3)
.build();
// download the object to file
Download download = tm.download(AWSS3Factory.S3_BUCKET, key, file);
// block until download finished
download.waitForCompletion();
tm.shutdownNow();
// print end time
Date end_date = new Date();
System.out.println(end_date.toString());
}
示例6: download
import com.amazonaws.services.s3.transfer.TransferManager; //導入方法依賴的package包/類
@Override
public Download download(String s3BucketName, String s3Key, File file, TransferManager transferManager)
{
return transferManager.download(s3BucketName, s3Key, file);
}