S3FileSystem extends FileSystem<S3ResourceId> { @VisibleForTesting CompleteMultipartUploadResult multipartCopy( S3ResourceId sourcePath, S3ResourceId destinationPath, ObjectMetadata sourceObjectMetadata) throws AmazonClientException { InitiateMultipartUploadRequest initiateUploadRequest = new InitiateMultipartUploadRequest(destinationPath.getBucket(), destinationPath.getKey()) .withStorageClass(options.getS3StorageClass()) .withObjectMetadata(sourceObjectMetadata); initiateUploadRequest.setSSECustomerKey(options.getSSECustomerKey()); InitiateMultipartUploadResult initiateUploadResult = amazonS3.get().initiateMultipartUpload(initiateUploadRequest); final String uploadId = initiateUploadResult.getUploadId(); List<PartETag> eTags = new ArrayList<>(); final long objectSize = sourceObjectMetadata.getContentLength(); if (objectSize == 0) { final CopyPartRequest copyPartRequest = new CopyPartRequest() .withSourceBucketName(sourcePath.getBucket()) .withSourceKey(sourcePath.getKey()) .withDestinationBucketName(destinationPath.getBucket()) .withDestinationKey(destinationPath.getKey()) .withUploadId(uploadId) .withPartNumber(1); copyPartRequest.setSourceSSECustomerKey(options.getSSECustomerKey()); copyPartRequest.setDestinationSSECustomerKey(options.getSSECustomerKey()); CopyPartResult copyPartResult = amazonS3.get().copyPart(copyPartRequest); eTags.add(copyPartResult.getPartETag()); } else { long bytePosition = 0; Integer uploadBufferSizeBytes = options.getS3UploadBufferSizeBytes(); for (int partNumber = 1; bytePosition < objectSize; partNumber++) { final CopyPartRequest copyPartRequest = new CopyPartRequest() .withSourceBucketName(sourcePath.getBucket()) .withSourceKey(sourcePath.getKey()) .withDestinationBucketName(destinationPath.getBucket()) .withDestinationKey(destinationPath.getKey()) .withUploadId(uploadId) .withPartNumber(partNumber) .withFirstByte(bytePosition) .withLastByte(Math.min(objectSize - 1, bytePosition + uploadBufferSizeBytes - 1)); copyPartRequest.setSourceSSECustomerKey(options.getSSECustomerKey()); copyPartRequest.setDestinationSSECustomerKey(options.getSSECustomerKey()); CopyPartResult copyPartResult = amazonS3.get().copyPart(copyPartRequest); eTags.add(copyPartResult.getPartETag()); bytePosition += uploadBufferSizeBytes; } } CompleteMultipartUploadRequest completeUploadRequest = new CompleteMultipartUploadRequest() .withBucketName(destinationPath.getBucket()) .withKey(destinationPath.getKey()) .withUploadId(uploadId) .withPartETags(eTags); return amazonS3.get().completeMultipartUpload(completeUploadRequest); } S3FileSystem(S3Options options);   }
@Test public void testMultipartCopy() { testMultipartCopy(s3Options()); testMultipartCopy(s3OptionsWithSSECustomerKey()); }