Search in sources :

Example 1 with CompleteMultipartUploadResult

use of com.emc.object.s3.bean.CompleteMultipartUploadResult in project pravega by pravega.

the class S3FileSystemImpl method completeMultipartUpload.

@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    try {
        partMap.forEach((index, copyPart) -> {
            if (copyPart.getKey() != copyPart.getSourceKey()) {
                Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
                Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
                try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
                    FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
                    targetChannel.transferFrom(sourceChannel, Files.size(targetPath), copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
                    targetChannel.close();
                    AclSize aclMap = this.aclMap.get(copyPart.getKey());
                    this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
                } catch (IOException e) {
                    throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
                }
            }
        });
    } finally {
        multipartUploads.remove(request.getKey());
    }
    return new CompleteMultipartUploadResult();
}
Also used : Path(java.nio.file.Path) CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) S3Exception(com.emc.object.s3.S3Exception) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) CompleteMultipartUploadResult(com.emc.object.s3.bean.CompleteMultipartUploadResult) Synchronized(lombok.Synchronized)

Aggregations

S3Exception (com.emc.object.s3.S3Exception)1 CompleteMultipartUploadResult (com.emc.object.s3.bean.CompleteMultipartUploadResult)1 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)1 IOException (java.io.IOException)1 FileChannel (java.nio.channels.FileChannel)1 Path (java.nio.file.Path)1 Synchronized (lombok.Synchronized)1