Search in sources :

Example 1 with MultipartUpload

use of org.jets3t.service.model.MultipartUpload in project hadoop by apache.

the class Jets3tNativeFileSystemStore method copyLargeFile.

public void copyLargeFile(S3Object srcObject, String dstKey) throws IOException {
    try {
        long partCount = srcObject.getContentLength() / multipartCopyBlockSize + (srcObject.getContentLength() % multipartCopyBlockSize > 0 ? 1 : 0);
        MultipartUpload multipartUpload = s3Service.multipartStartUpload(bucket.getName(), dstKey, srcObject.getMetadataMap());
        List<MultipartPart> listedParts = new ArrayList<MultipartPart>();
        for (int i = 0; i < partCount; i++) {
            long byteRangeStart = i * multipartCopyBlockSize;
            long byteLength;
            if (i < partCount - 1) {
                byteLength = multipartCopyBlockSize;
            } else {
                byteLength = srcObject.getContentLength() % multipartCopyBlockSize;
                if (byteLength == 0) {
                    byteLength = multipartCopyBlockSize;
                }
            }
            MultipartPart copiedPart = s3Service.multipartUploadPartCopy(multipartUpload, i + 1, bucket.getName(), srcObject.getKey(), null, null, null, null, byteRangeStart, byteRangeStart + byteLength - 1, null);
            listedParts.add(copiedPart);
        }
        Collections.reverse(listedParts);
        s3Service.multipartCompleteUpload(multipartUpload, listedParts);
    } catch (ServiceException e) {
        handleException(e, srcObject.getKey());
    }
}
Also used : MultipartPart(org.jets3t.service.model.MultipartPart) ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) ArrayList(java.util.ArrayList) MultipartUpload(org.jets3t.service.model.MultipartUpload)

Aggregations

ArrayList (java.util.ArrayList)1 S3ServiceException (org.jets3t.service.S3ServiceException)1 ServiceException (org.jets3t.service.ServiceException)1 MultipartPart (org.jets3t.service.model.MultipartPart)1 MultipartUpload (org.jets3t.service.model.MultipartUpload)1