当前位置: 首页>>代码示例>>Java>>正文


Java TransferManager类代码示例

本文整理汇总了Java中com.amazonaws.services.s3.transfer.TransferManager的典型用法代码示例。如果您正苦于以下问题:Java TransferManager类的具体用法?Java TransferManager怎么用?Java TransferManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransferManager类属于com.amazonaws.services.s3.transfer包,在下文中一共展示了TransferManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadDir

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
public static void uploadDir(String dir_path, String bucket_name,
        String key_prefix, boolean recursive, boolean pause)
{
    System.out.println("directory: " + dir_path + (recursive ?
                " (recursive)" : "") + (pause ? " (pause)" : ""));

    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload xfer = xfer_mgr.uploadDirectory(bucket_name,
                key_prefix, new File(dir_path), recursive);
        // 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,代码来源:XferMgrUpload.java

示例2: 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

示例3: uploadDirWithSubprogress

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
public static void uploadDirWithSubprogress(String dir_path,
        String bucket_name, String key_prefix, boolean recursive,
        boolean pause)
{
    System.out.println("directory: " + dir_path + (recursive ?
                " (recursive)" : "") + (pause ? " (pause)" : ""));

    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload multi_upload = xfer_mgr.uploadDirectory(
                bucket_name, key_prefix, new File(dir_path), recursive);
        // loop with Transfer.isDone()
        XferMgrProgress.showMultiUploadProgress(multi_upload);
        // or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(multi_upload);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:22,代码来源:XferMgrProgress.java

示例4: uploadToS3

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
private String uploadToS3(String bucket, String key, MultipartFile file) {
    final AmazonS3 s3 = s3ClientFactory.createClient();
    final TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(s3).build();
    try {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(file.getSize());
        metadata.setContentType(file.getContentType());

        byte[] resultByte = DigestUtils.md5(file.getBytes());
        String streamMD5 = new String(Base64.encodeBase64(resultByte));
        metadata.setContentMD5(streamMD5);

        Upload upload = transferManager.upload(bucket, key, file.getInputStream(), metadata);
        upload.waitForCompletion();
        return streamMD5;
    } catch (AmazonServiceException | InterruptedException | IOException e) {
        logger.error("Error uploading file: {}", e.toString());
        return null;
    } finally {
        transferManager.shutdownNow();
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:23,代码来源:StorageBrokerImpl.java

示例5: getTransferManager

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
/**
 * Gets an Amazon transfer manager.
 *
 * @return a transfer manager
 */
public TransferManager getTransferManager() {
    if (transferManager == null) {
        transferManager = TransferManagerBuilder.standard().withS3Client(getAmazonS3Client()).build();
    }
    return transferManager;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:12,代码来源:AmazonS3Template.java

示例6: copyCheckTransferManagerIsShutdown

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
@Test
public void copyCheckTransferManagerIsShutdown() throws Exception {
  client.putObject("source", "data", inputData);
  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/");
  List<Path> sourceSubLocations = new ArrayList<>();

  TransferManagerFactory mockedTransferManagerFactory = Mockito.mock(TransferManagerFactory.class);
  TransferManager mockedTransferManager = Mockito.mock(TransferManager.class);
  when(mockedTransferManagerFactory.newInstance(any(AmazonS3.class), eq(s3S3CopierOptions)))
      .thenReturn(mockedTransferManager);
  Copy copy = Mockito.mock(Copy.class);
  when(mockedTransferManager.copy(any(CopyObjectRequest.class), any(AmazonS3.class),
      any(TransferStateChangeListener.class))).thenReturn(copy);
  TransferProgress transferProgress = new TransferProgress();
  when(copy.getProgress()).thenReturn(transferProgress);
  S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
      mockedTransferManagerFactory, listObjectsRequestFactory, registry, s3S3CopierOptions);
  s3s3Copier.copy();
  verify(mockedTransferManager).shutdownNow();
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:22,代码来源:S3S3CopierTest.java

示例7: copyCheckTransferManagerIsShutdownWhenSubmittingJobExceptionsAreThrown

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
@Test
public void copyCheckTransferManagerIsShutdownWhenSubmittingJobExceptionsAreThrown() throws Exception {
  client.putObject("source", "data", inputData);
  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/");
  List<Path> sourceSubLocations = new ArrayList<>();

  TransferManagerFactory mockedTransferManagerFactory = Mockito.mock(TransferManagerFactory.class);
  TransferManager mockedTransferManager = Mockito.mock(TransferManager.class);
  when(mockedTransferManagerFactory.newInstance(any(AmazonS3.class), eq(s3S3CopierOptions)))
      .thenReturn(mockedTransferManager);
  when(mockedTransferManager.copy(any(CopyObjectRequest.class), any(AmazonS3.class),
      any(TransferStateChangeListener.class))).thenThrow(new AmazonServiceException("MyCause"));
  S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
      mockedTransferManagerFactory, listObjectsRequestFactory, registry, s3S3CopierOptions);
  try {
    s3s3Copier.copy();
    fail("exception should have been thrown");
  } catch (CircusTrainException e) {
    verify(mockedTransferManager).shutdownNow();
    assertThat(e.getCause().getMessage(), startsWith("MyCause"));
  }
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:24,代码来源:S3S3CopierTest.java

示例8: copyCheckTransferManagerIsShutdownWhenCopyExceptionsAreThrown

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
@Test
public void copyCheckTransferManagerIsShutdownWhenCopyExceptionsAreThrown() throws Exception {
  client.putObject("source", "data", inputData);
  Path sourceBaseLocation = new Path("s3://source/");
  Path replicaLocation = new Path("s3://target/");
  List<Path> sourceSubLocations = new ArrayList<>();

  TransferManagerFactory mockedTransferManagerFactory = Mockito.mock(TransferManagerFactory.class);
  TransferManager mockedTransferManager = Mockito.mock(TransferManager.class);
  when(mockedTransferManagerFactory.newInstance(any(AmazonS3.class), eq(s3S3CopierOptions)))
      .thenReturn(mockedTransferManager);
  Copy copy = Mockito.mock(Copy.class);
  when(copy.getProgress()).thenReturn(new TransferProgress());
  when(mockedTransferManager.copy(any(CopyObjectRequest.class), any(AmazonS3.class),
      any(TransferStateChangeListener.class))).thenReturn(copy);
  doThrow(new AmazonClientException("cause")).when(copy).waitForCompletion();
  S3S3Copier s3s3Copier = new S3S3Copier(sourceBaseLocation, sourceSubLocations, replicaLocation, s3ClientFactory,
      mockedTransferManagerFactory, listObjectsRequestFactory, registry, s3S3CopierOptions);
  try {
    s3s3Copier.copy();
    fail("exception should have been thrown");
  } catch (CircusTrainException e) {
    verify(mockedTransferManager).shutdownNow();
    assertThat(e.getCause().getMessage(), is("cause"));
  }
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:27,代码来源:S3S3CopierTest.java

示例9: testS3Persister

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
@Test
public void testS3Persister() throws Exception {
    Upload upload = mock(Upload.class);
    when(upload.waitForUploadResult()).thenReturn(new UploadResult());
    TransferManager transferManager = mock(TransferManager.class);
    when(transferManager.upload(anyString(), anyString(), any())).thenReturn(upload);

    S3Persister s3Persister = new S3Persister(transferManager, "foo");
    s3Persister.saveMetrics("foo", "bar");

    verify(transferManager, times(1)).upload(anyString(), anyString(), any());
    verify(transferManager, times(1)).shutdownNow();
    verifyNoMoreInteractions(transferManager);
    verify(upload, times(1)).waitForCompletion();
    verifyNoMoreInteractions(upload);
    assertFalse(new File("foo").exists());
}
 
开发者ID:awslabs,项目名称:emr-workload-profiler,代码行数:18,代码来源:S3PersisterTest.java

示例10: create

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
@Override
@Guarded(by = STARTED)
public Blob create(final InputStream blobData, final Map<String, String> headers) {
  checkNotNull(blobData);

  return create(headers, destination -> {
      try (InputStream data = blobData) {
        MetricsInputStream input = new MetricsInputStream(data);
        TransferManager transferManager = new TransferManager(s3);
        transferManager.upload(getConfiguredBucket(), destination, input, new ObjectMetadata())
            .waitForCompletion();
        return input.getMetrics();
      } catch (InterruptedException e) {
        throw new BlobStoreException("error uploading blob", e, null);
      }
    });
}
 
开发者ID:sonatype,项目名称:nexus-blobstore-s3,代码行数:18,代码来源:S3BlobStore.java

示例11: create

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
/**
 * Constructs a new watcher for copy operation, and then immediately submits
 * it to the thread pool.
 *
 * @param manager
 *            The {@link TransferManager} that owns this copy request.
 * @param threadPool
 *            The {@link ExecutorService} to which we should submit new
 *            tasks.
 * @param multipartCopyCallable
 *            The callable responsible for processing the copy
 *            asynchronously
 * @param copyObjectRequest
 *            The original CopyObject request
 */
public static CopyMonitor create(
        TransferManager manager,
        CopyImpl transfer,
        ExecutorService threadPool,
        CopyCallable multipartCopyCallable,
        CopyObjectRequest copyObjectRequest,
        ProgressListenerChain progressListenerChain) {

    CopyMonitor copyMonitor = new CopyMonitor(manager, transfer,
            threadPool, multipartCopyCallable, copyObjectRequest,
            progressListenerChain);
    Future<CopyResult> thisFuture = threadPool.submit(copyMonitor);
    // Use an atomic compareAndSet to prevent a possible race between the
    // setting of the CopyMonitor's futureReference, and setting the
    // CompleteMultipartCopy's futureReference within the call() method.
    // We only want to set the futureReference to CopyMonitor's futureReference if the
    // current value is null, otherwise the futureReference that's set is
    // CompleteMultipartCopy's which is ultimately what we want.
    copyMonitor.futureReference.compareAndSet(null, thisFuture);
    return copyMonitor;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:37,代码来源:CopyMonitor.java

示例12: create

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
/**
 * Constructs a new upload watcher and then immediately submits it to
 * the thread pool.
 *
 * @param manager
 *            The {@link TransferManager} that owns this upload.
 * @param transfer
 *            The transfer being processed.
 * @param threadPool
 *            The {@link ExecutorService} to which we should submit new
 *            tasks.
 * @param multipartUploadCallable
 *            The callable responsible for processing the upload
 *            asynchronously
 * @param putObjectRequest
 *            The original putObject request
 * @param progressListenerChain
 *            A chain of listeners that wish to be notified of upload
 *            progress
 */
public static UploadMonitor create(
        TransferManager manager,
        UploadImpl transfer,
        ExecutorService threadPool,
        UploadCallable multipartUploadCallable,
        PutObjectRequest putObjectRequest,
        ProgressListenerChain progressListenerChain) {

    UploadMonitor uploadMonitor = new UploadMonitor(manager, transfer,
            threadPool, multipartUploadCallable, putObjectRequest,
            progressListenerChain);
    Future<UploadResult> thisFuture = threadPool.submit(uploadMonitor);
    // Use an atomic compareAndSet to prevent a possible race between the
    // setting of the UploadMonitor's futureReference, and setting the
    // CompleteMultipartUpload's futureReference within the call() method.
    // We only want to set the futureReference to UploadMonitor's futureReference if the
    // current value is null, otherwise the futureReference that's set is
    // CompleteMultipartUpload's which is ultimately what we want.
    uploadMonitor.futureReference.compareAndSet(null, thisFuture);
    return uploadMonitor;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:42,代码来源:UploadMonitor.java

示例13: shouldUploadInParallel

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
/**
 * Tests if an object can be uploaded asynchronously
 *
 * @throws Exception not expected
 */
@Test
public void shouldUploadInParallel() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);

  final TransferManager transferManager = createDefaultTransferManager();
  final Upload upload =
      transferManager.upload(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  final UploadResult uploadResult = upload.waitForUploadResult();

  assertThat(uploadResult.getKey(), equalTo(UPLOAD_FILE_NAME));

  final S3Object getResult = s3Client.getObject(BUCKET_NAME, UPLOAD_FILE_NAME);
  assertThat(getResult.getKey(), equalTo(UPLOAD_FILE_NAME));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:22,代码来源:AmazonClientUploadIT.java

示例14: checkRangeDownloads

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
/**
 * Verify that range-downloads work.
 *
 * @throws Exception not expected
 */
@Test
public void checkRangeDownloads() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);

  final TransferManager transferManager = createDefaultTransferManager();
  final Upload upload =
      transferManager.upload(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  upload.waitForUploadResult();

  final File downloadFile = File.createTempFile(UUID.randomUUID().toString(), null);
  transferManager
      .download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(1, 2),
          downloadFile)
      .waitForCompletion();
  assertThat("Invalid file length", downloadFile.length(), is(2L));

  transferManager
      .download(new GetObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME).withRange(0, 1000),
          downloadFile)
      .waitForCompletion();
  assertThat("Invalid file length", downloadFile.length(), is(uploadFile.length()));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:30,代码来源:AmazonClientUploadIT.java

示例15: createTransferManager

import com.amazonaws.services.s3.transfer.TransferManager; //导入依赖的package包/类
private TransferManager createTransferManager(final long multipartUploadThreshold,
    final long multipartUploadPartSize,
    final long multipartCopyThreshold,
    final long multipartCopyPartSize) {
  final ThreadFactory threadFactory = new ThreadFactory() {
    private int threadCount = 1;

    @Override
    public Thread newThread(final Runnable r) {
      final Thread thread = new Thread(r);
      thread.setName("s3-transfer-" + threadCount++);

      return thread;
    }
  };

  return TransferManagerBuilder.standard()
      .withS3Client(s3Client)
      .withExecutorFactory(() -> Executors.newFixedThreadPool(THREAD_COUNT, threadFactory))
      .withMultipartUploadThreshold(multipartUploadThreshold)
      .withMinimumUploadPartSize(multipartUploadPartSize)
      .withMultipartCopyPartSize(multipartCopyPartSize)
      .withMultipartCopyThreshold(multipartCopyThreshold)
      .build();
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:26,代码来源:AmazonClientUploadIT.java


注:本文中的com.amazonaws.services.s3.transfer.TransferManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。