@Override public final CopyPartResult copyPartSecurely(CopyPartRequest copyPartRequest) { String uploadId = copyPartRequest.getUploadId(); T uploadContext = multipartUploadContexts.get(uploadId); CopyPartResult result = s3.copyPart(copyPartRequest); if (uploadContext != null && !uploadContext.hasFinalPartBeenSeen()) uploadContext.setHasFinalPartBeenSeen(true); return result; }
@Override public CopyPartResult copyPartSecurely(CopyPartRequest req) { return defaultCryptoMode == EncryptionOnly ? eo.copyPartSecurely(req) : ae.copyPartSecurely(req) ; }
static List<PartETag> GetETags(List<CopyPartResult> responses) { List<PartETag> etags = new ArrayList<PartETag>(); for (CopyPartResult response : responses) { etags.add(new PartETag(response.getPartNumber(), response.getETag())); } return etags; }
@Override public CopyPartResult copyPart(CopyPartRequest copyPartRequest) throws AmazonClientException, AmazonServiceException { return delegate.copyPart(copyPartRequest); }
@Override public CopyPartResult copyPart(CopyPartRequest copyPartRequest) { return crypto.copyPartSecurely(copyPartRequest); }
@Override public CopyPartResult copyPart(CopyPartRequest req) { return AmazonS3EncryptionClient.super.copyPart(req); }
@Override public CopyPartResult copyPart(CopyPartRequest copyPartRequest) { return call(() -> getDelegate().copyPart(copyPartRequest)); }
private CompleteMultipartUploadResult copyMultipartFile(Bucket srcBucket, Bucket targetBucket, String fileName, long size) { // Create lists to hold copy responses List<CopyPartResult> copyResponses = new ArrayList<CopyPartResult>(); // Step 2: Initialize InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest(targetBucket.getName(), targetBucket.getPath() + SEPARATOR + fileName); InitiateMultipartUploadResult initResult = s3Client.initiateMultipartUpload(initiateRequest); // Step 4. Copy parts. long partSize = 5 * (long)Math.pow(2.0, 20.0); // 5 MB long bytePosition = 0; for (int i = 1; bytePosition < size; i++) { // Step 5. Save copy response. CopyPartRequest copyRequest = new CopyPartRequest() .withDestinationBucketName(targetBucket.getName()) .withDestinationKey(targetBucket.getPath() + SEPARATOR + fileName) .withSourceBucketName(srcBucket.getName()) .withSourceKey(srcBucket.getPath() + SEPARATOR + fileName) .withUploadId(initResult.getUploadId()) .withFirstByte(bytePosition) .withLastByte(bytePosition + partSize -1 >= size ? size - 1 : bytePosition + partSize - 1) .withPartNumber(i); copyResponses.add(s3Client.copyPart(copyRequest)); bytePosition += partSize; } CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest( targetBucket.getName(), targetBucket.getPath() + SEPARATOR + fileName, initResult.getUploadId(), GetETags(copyResponses)); // Step 7. Complete copy operation. CompleteMultipartUploadResult completeUploadResponse = s3Client.completeMultipartUpload(completeRequest); return completeUploadResponse; }
@Override public CopyPartResult copyPart(CopyPartRequest copyPartRequest) throws AmazonClientException { return null; }
@Test public void testMultipartCopy() throws Exception { // B2 requires two parts to issue an MPU assumeTrue(!blobStoreType.equals("b2")); String sourceBlobName = "testMultipartCopy-source"; String targetBlobName = "testMultipartCopy-target"; ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); client.putObject(containerName, sourceBlobName, BYTE_SOURCE.openStream(), metadata); InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest(containerName, targetBlobName); InitiateMultipartUploadResult initResult = client.initiateMultipartUpload(initiateRequest); String uploadId = initResult.getUploadId(); CopyPartRequest copyRequest = new CopyPartRequest() .withDestinationBucketName(containerName) .withDestinationKey(targetBlobName) .withSourceBucketName(containerName) .withSourceKey(sourceBlobName) .withUploadId(uploadId) .withFirstByte(0L) .withLastByte(BYTE_SOURCE.size() - 1) .withPartNumber(1); CopyPartResult copyPartResult = client.copyPart(copyRequest); CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest( containerName, targetBlobName, uploadId, ImmutableList.of(copyPartResult.getPartETag())); CompleteMultipartUploadResult completeUploadResponse = client.completeMultipartUpload(completeRequest); S3Object object = client.getObject(containerName, targetBlobName); assertThat(object.getObjectMetadata().getContentLength()).isEqualTo( BYTE_SOURCE.size()); try (InputStream actual = object.getObjectContent(); InputStream expected = BYTE_SOURCE.openStream()) { assertThat(actual).hasContentEqualTo(expected); } }
@Override public CopyPartResult copyPart(CopyPartRequest copyPartRequest) throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub return null; }
public abstract CopyPartResult copyPart(CopyPartRequest req);
public abstract CopyPartResult copyPartSecurely(CopyPartRequest req);
public CopyPartResult copyPart(CopyPartRequest req);