当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMetadata.getContentLength方法代码示例

本文整理汇总了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;
  }
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:48,代码来源:SmartOSSClient.java

示例2: isMultipartCopy

import com.aliyun.oss.model.ObjectMetadata; //导入方法依赖的package包/类
private boolean isMultipartCopy(ObjectMetadata metadata) {
  return (metadata.getContentLength() > configuration.getMultipartCopyThreshold());
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:4,代码来源:SmartOSSClient.java


注:本文中的com.aliyun.oss.model.ObjectMetadata.getContentLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。