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


Java CopyObjectRequest类代码示例

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


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

示例1: move

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
            blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }

        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });

    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:S3BlobContainer.java

示例2: copyObject

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Override
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    String sourceBlobName = copyObjectRequest.getSourceKey();
    String targetBlobName = copyObjectRequest.getDestinationKey();

    if (!blobs.containsKey(sourceBlobName)) {
        throw new AmazonS3Exception("Source blob [" +
                sourceBlobName + "] does not exist.");
    }

    if (blobs.containsKey(targetBlobName)) {
        throw new AmazonS3Exception("Target blob [" +
                targetBlobName + "] already exists.");
    }

    blobs.put(targetBlobName, blobs.get(sourceBlobName));
    return new CopyObjectResult(); // nothing is done with it
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MockAmazonS3.java

示例3: copyCheckTransferManagerIsShutdown

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的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

示例4: copyCheckTransferManagerIsShutdownWhenSubmittingJobExceptionsAreThrown

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的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

示例5: copyCheckTransferManagerIsShutdownWhenCopyExceptionsAreThrown

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的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

示例6: create

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的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

示例7: shouldCopyObject

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
/**
 * Puts an Object; Copies that object to a new bucket; Downloads the object from the new
 * bucket; compares checksums
 * of original and copied object
 *
 * @throws Exception if an Exception occurs
 */
@Test
public void shouldCopyObject() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String sourceKey = UPLOAD_FILE_NAME;
  final String destinationBucketName = "destinationBucket";
  final String destinationKey = "copyOf/" + sourceKey;

  final PutObjectResult putObjectResult =
      s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  s3Client.copyObject(copyObjectRequest);

  final com.amazonaws.services.s3.model.S3Object copiedObject =
      s3Client.getObject(destinationBucketName, destinationKey);

  final String copiedHash = HashUtil.getDigest(copiedObject.getObjectContent());
  copiedObject.close();

  assertThat("Sourcefile and copied File should have same Hashes",
      copiedHash,
      is(equalTo(putObjectResult.getETag())));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:32,代码来源:AmazonClientUploadIT.java

示例8: shouldCopyObjectEncrypted

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
/**
 * Puts an Object; Copies that object to a new bucket; Downloads the object from the new
 * bucket; compares checksums
 * of original and copied object
 *
 * @throws Exception if an Exception occurs
 */
@Test
public void shouldCopyObjectEncrypted() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String sourceKey = UPLOAD_FILE_NAME;
  final String destinationBucketName = "destinationBucket";
  final String destinationKey = "copyOf/" + sourceKey;

  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  copyObjectRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_ENC_KEYREF));

  final CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);

  final ObjectMetadata metadata =
      s3Client.getObjectMetadata(destinationBucketName, destinationKey);

  final InputStream uploadFileIS = new FileInputStream(uploadFile);
  final String uploadHash = HashUtil.getDigest(TEST_ENC_KEYREF, uploadFileIS);
  assertThat("ETag should match", copyObjectResult.getETag(), is(uploadHash));
  assertThat("Files should have the same length", metadata.getContentLength(),
      is(uploadFile.length()));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:32,代码来源:AmazonClientUploadIT.java

示例9: shouldNotObjectCopyWithWrongEncryptionKey

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
/**
 * Tests that an object wont be copied with wrong encryption Key
 *
 * @throws Exception if an Exception occurs
 */
@Test
public void shouldNotObjectCopyWithWrongEncryptionKey() {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String sourceKey = UPLOAD_FILE_NAME;
  final String destinationBucketName = "destinationBucket";
  final String destinationKey = "copyOf" + sourceKey;

  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  copyObjectRequest
      .setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_WRONG_KEYREF));

  thrown.expect(AmazonS3Exception.class);
  thrown.expectMessage(containsString("Status Code: 400; Error Code: KMS.NotFoundException"));
  s3Client.copyObject(copyObjectRequest);
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:24,代码来源:AmazonClientUploadIT.java

示例10: storeMimeType

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Override
protected void storeMimeType(BinaryValue binaryValue, String mimeType)
    throws BinaryStoreException {
    try {
        String key = binaryValue.getKey().toString();
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
        metadata.setContentType(mimeType);

        // Update the object in place
        CopyObjectRequest copyRequest =
            new CopyObjectRequest(bucketName, key, bucketName, key);
        copyRequest.setNewObjectMetadata(metadata);
        s3Client.copyObject(copyRequest);
    } catch (AmazonClientException e) {
        throw new BinaryStoreException(e);
    }
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:18,代码来源:S3BinaryStore.java

示例11: setS3ObjectUserProperty

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
private void setS3ObjectUserProperty(BinaryKey binaryKey,
                                     String metadataKey,
                                     String metadataValue)
    throws BinaryStoreException {
    try {
        String key = binaryKey.toString();
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key);
        Map<String, String> userMetadata = metadata.getUserMetadata();

        if(null != metadataValue &&
           metadataValue.equals(userMetadata.get(metadataKey))) {
           return; // The key/value pair already exists in user metadata, skip update
        }

        userMetadata.put(metadataKey, metadataValue);
        metadata.setUserMetadata(userMetadata);

        // Update the object in place
        CopyObjectRequest copyRequest =
            new CopyObjectRequest(bucketName, key, bucketName, key);
        copyRequest.setNewObjectMetadata(metadata);
        s3Client.copyObject(copyRequest);
    } catch (AmazonClientException e) {
        throw new BinaryStoreException(e);
    }
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:27,代码来源:S3BinaryStore.java

示例12: testStoreMimeType

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Test
public void testStoreMimeType() throws BinaryStoreException {
    expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY))
        .andReturn(new ObjectMetadata());
    Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance();
    expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null);

    replayAll();

    BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT);
    s3BinaryStore.storeMimeType(binaryValue, TEST_MIME);

    CopyObjectRequest copyRequest = copyRequestCapture.getValue();
    assertEquals(BUCKET, copyRequest.getSourceBucketName());
    assertEquals(BUCKET, copyRequest.getDestinationBucketName());
    assertEquals(TEST_KEY, copyRequest.getSourceKey());
    assertEquals(TEST_KEY, copyRequest.getDestinationKey());
    assertEquals(TEST_MIME, copyRequest.getNewObjectMetadata().getContentType());
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:20,代码来源:S3BinaryStoreTest.java

示例13: testStoreExtractedText

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Test
public void testStoreExtractedText() throws BinaryStoreException {
    String extractedText = "text-that-has-been-extracted";

    expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY))
        .andReturn(new ObjectMetadata());
    Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance();
    expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null);

    replayAll();

    BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT);
    s3BinaryStore.storeExtractedText(binaryValue, extractedText);

    CopyObjectRequest copyRequest = copyRequestCapture.getValue();
    assertEquals(BUCKET, copyRequest.getSourceBucketName());
    assertEquals(BUCKET, copyRequest.getDestinationBucketName());
    assertEquals(TEST_KEY, copyRequest.getSourceKey());
    assertEquals(TEST_KEY, copyRequest.getDestinationKey());
    assertEquals(extractedText, copyRequest.getNewObjectMetadata()
                                           .getUserMetadata()
                                           .get(s3BinaryStore.EXTRACTED_TEXT_KEY));
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:24,代码来源:S3BinaryStoreTest.java

示例14: testStoreValueExisting

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Test
public void testStoreValueExisting() throws BinaryStoreException, IOException {
    String valueToStore = "value-to-store";

    expect(s3Client.doesObjectExist(eq(BUCKET), isA(String.class))).andReturn(true);
    expect(s3Client.getObjectMetadata(eq(BUCKET), isA(String.class)))
        .andReturn(new ObjectMetadata());
    ObjectMetadata objMeta = new ObjectMetadata();
    Map<String, String> userMeta = new HashMap<>();
    userMeta.put(s3BinaryStore.UNUSED_KEY, String.valueOf(true));
    objMeta.setUserMetadata(userMeta);
    Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance();
    expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null);

    replayAll();

    s3BinaryStore.storeValue(new StringInputStream(valueToStore), true);
    ObjectMetadata newObjMeta = copyRequestCapture.getValue().getNewObjectMetadata();
    assertEquals(String.valueOf(true),
                 newObjMeta.getUserMetadata().get(s3BinaryStore.UNUSED_KEY));
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:22,代码来源:S3BinaryStoreTest.java

示例15: testMarkAsUsed

import com.amazonaws.services.s3.model.CopyObjectRequest; //导入依赖的package包/类
@Test
public void testMarkAsUsed() throws BinaryStoreException {
    ObjectMetadata objMeta = new ObjectMetadata();
    Map<String, String> userMeta = new HashMap<>();
    // Existing value of unused property set to true (so file is considered not used)
    userMeta.put(s3BinaryStore.UNUSED_KEY, String.valueOf(true));
    objMeta.setUserMetadata(userMeta);
    expect(s3Client.getObjectMetadata(eq(BUCKET), isA(String.class)))
        .andReturn(objMeta);
    Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance();
    expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null);

    replayAll();

    s3BinaryStore.markAsUsed(Collections.singleton(new BinaryKey(TEST_KEY)));
    ObjectMetadata newObjMeta = copyRequestCapture.getValue().getNewObjectMetadata();
    assertEquals(String.valueOf(false),
                 newObjMeta.getUserMetadata().get(s3BinaryStore.UNUSED_KEY));
}
 
开发者ID:fcrepo4-labs,项目名称:modeshape-s3-binary-store,代码行数:20,代码来源:S3BinaryStoreTest.java


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