本文整理汇总了Java中com.aliyun.oss.model.ObjectMetadata.getContentLength方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMetadata.getContentLength方法的具体用法?Java ObjectMetadata.getContentLength怎么用?Java ObjectMetadata.getContentLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.aliyun.oss.model.ObjectMetadata
的用法示例。
在下文中一共展示了ObjectMetadata.getContentLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMultiPartCopy
import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
private CopyObjectResult doMultiPartCopy(CopyObjectRequest copyObjectRequest, ObjectMetadata metadata) {
//Claim a new upload id for your target bucket
InitiateMultipartUploadRequest initiateMultipartUploadRequest =
new InitiateMultipartUploadRequest(copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
InitiateMultipartUploadResult initiateMultipartUploadResult = this.initiateMultipartUpload(initiateMultipartUploadRequest);
String uploadId = initiateMultipartUploadResult.getUploadId();
//Calculate how many parts to be divided
long optimalPartSize = calculateOptimalPartSizeForCopy(configuration, metadata.getContentLength());
long objectSize = metadata.getContentLength();
int totalParts = (int) Math.ceil((double) objectSize / optimalPartSize);
//Upload multi-parts by copy mode
System.out.println("Begin to upload multiparts by copy mode to OSS\n");
List<Future<PartETag>> futures = new ArrayList<Future<PartETag>>();
for (int i = 0; i < totalParts; i++) {
long startPos = i * optimalPartSize;
long curPartSize = (i + 1 == totalParts) ? (objectSize - startPos) : optimalPartSize;
//Construct UploadPartCopyRequest
UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(
copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey());
uploadPartCopyRequest.setUploadId(uploadId);
uploadPartCopyRequest.setPartSize(curPartSize);
uploadPartCopyRequest.setBeginIndex(startPos);
uploadPartCopyRequest.setPartNumber(i + 1);
futures.add(threadPoolExecutor.submit(new PartCopyCallable(uploadPartCopyRequest)));
}
List<PartETag> partETags = collectPartETags(futures);
//Verify whether all parts are finished
if (partETags.size() != totalParts) {
throw new IllegalStateException("Upload multi-parts fail due to some parts are not finished yet");
} else {
LOG.info("Succeed to complete multi-parts copy from object named {} to {}", copyObjectRequest.getSourceKey(), copyObjectRequest.getDestinationKey());
}
//Complete to upload multi-parts
System.out.println("Completing to upload multiparts\n");
CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(
copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), uploadId, partETags);
CompleteMultipartUploadResult completeMultipartUploadResult = this.completeMultipartUpload(completeMultipartUploadRequest);
CopyObjectResult result = new CopyObjectResult();
result.setEtag(completeMultipartUploadResult.getETag());
return result;
}
示例2: isMultipartCopy
import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
private boolean isMultipartCopy(ObjectMetadata metadata) {
return (metadata.getContentLength() > configuration.getMultipartCopyThreshold());
}