@Override public CopyPartResult copyPart(CopyPartRequest request) { CopyPartResult result = executeRequest(client, request, CopyPartResult.class); result.setPartNumber(request.getPartNumber()); return result; }
public CopyPartRequest withSourceRange(Range sourceRange) { setSourceRange(sourceRange); return this; } }
@Override public CopyPartResult copyPart(CopyPartRequest request) { Range range = request.getSourceRange(); if (range.getLast() == -1) { range = Range.fromOffsetLength(0, aclMap.get(request.getSourceKey()).getSize()); request.withSourceRange(range); } CopyObjectResult result = executeRequest(client, request, CopyObjectResult.class); CopyPartResult retVal = new CopyPartResult(); retVal.setPartNumber(request.getPartNumber()); retVal.setETag(result.getETag()); return retVal; } }
@Override public CopyPartResult copyPart(CopyPartRequest request) { Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey()); if (partMap == null) { throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", ""); } partMap.put(request.getPartNumber(), request); CopyPartResult result = new CopyPartResult(); result.setPartNumber(request.getPartNumber()); result.setETag(request.getUploadId()); return result; }
@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().equals(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(); }
CopyPartRequest copyRequest = new CopyPartRequest(config.getBucket(), targetPath, config.getBucket(), targetPath, uploadId, 1).withSourceRange(Range.fromOffsetLength(0, offset)); CopyPartResult copyResult = client.copyPart(copyRequest); long objectSize = metadataResult.getContentLength(); // in bytes copyRequest = new CopyPartRequest(config.getBucket(), config.getRoot() + sourceSegment, config.getBucket(), targetPath, uploadId, 2).withSourceRange(Range.fromOffsetLength(0, objectSize));