當前位置: 首頁>>代碼示例>>Java>>正文


Java TransferManager.download方法代碼示例

本文整理匯總了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();
}
 
開發者ID:darshanmaiya,項目名稱:MCSFS,代碼行數:17,代碼來源:S3Store.java

示例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);
    }
}
 
開發者ID:mesosphere,項目名稱:dcos-cassandra-service,代碼行數:26,代碼來源:S3StorageDriver.java

示例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();
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:21,代碼來源:XferMgrDownload.java

示例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();
}
 
開發者ID:qaprosoft,項目名稱:carina,代碼行數:31,代碼來源:AmazonS3Manager.java

示例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());
}
 
開發者ID:EMCECS,項目名稱:ecs-samples,代碼行數:32,代碼來源:_10_ReadLargeObjectTM.java

示例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);
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:6,代碼來源:S3OperationsImpl.java


注:本文中的com.amazonaws.services.s3.transfer.TransferManager.download方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。