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


Java PutObjectRequest.setGeneralProgressListener方法代码示例

本文整理汇总了Java中com.amazonaws.services.s3.model.PutObjectRequest.setGeneralProgressListener方法的典型用法代码示例。如果您正苦于以下问题:Java PutObjectRequest.setGeneralProgressListener方法的具体用法?Java PutObjectRequest.setGeneralProgressListener怎么用?Java PutObjectRequest.setGeneralProgressListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.s3.model.PutObjectRequest的用法示例。


在下文中一共展示了PutObjectRequest.setGeneralProgressListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putObject

import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
private void putObject() throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Executing regular upload for bucket '{}' key '{}'", bucket,
        key);
  }
  final ObjectMetadata om = createDefaultMetadata();
  om.setContentLength(buffer.size());
  final PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key,
      new ByteArrayInputStream(buffer.toByteArray()), om);
  putObjectRequest.setCannedAcl(cannedACL);
  putObjectRequest.setGeneralProgressListener(progressListener);
  ListenableFuture<PutObjectResult> putObjectResult =
      executorService.submit(new Callable<PutObjectResult>() {
        @Override
        public PutObjectResult call() throws Exception {
          return client.putObject(putObjectRequest);
        }
      });
  //wait for completion
  try {
    putObjectResult.get();
  } catch (InterruptedException ie) {
    LOG.warn("Interrupted object upload:" + ie, ie);
    Thread.currentThread().interrupt();
  } catch (ExecutionException ee) {
    throw new IOException("Regular upload failed", ee.getCause());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:S3AFastOutputStream.java

示例2: uploadTextToS3Bucket

import com.amazonaws.services.s3.model.PutObjectRequest; //导入方法依赖的package包/类
public void uploadTextToS3Bucket(String bucketName, String key, String content, String storageClass) throws TranscodeException{
	ObjectMetadata objectMetaData = new ObjectMetadata();
	byte[] bytes = content.getBytes();
	objectMetaData.setContentLength(bytes.length);
	objectMetaData.setContentType("text/html; charset=utf-8");
	try {
		ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
		PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, inputStream, objectMetaData);
		if (storageClass.equalsIgnoreCase(StorageClass.ReducedRedundancy.name())) {
			putObjectRequest.setStorageClass(StorageClass.ReducedRedundancy);
		}
		
		final long fileSizeInBytes = bytes.length;
		
		putObjectRequest.setGeneralProgressListener(new ProgressListener() {
			
			private long bytesTransferred = 0;
			
			private int currentPercentage = 0;
			
			@Override
			public void progressChanged(ProgressEvent progressEvent) {
				bytesTransferred += progressEvent.getBytesTransferred();
				int percentTransferred = (int) (bytesTransferred * 100 / fileSizeInBytes);
				if (percentTransferred%10 == 0 && percentTransferred != currentPercentage) {
					logger.info("Transferred {}% of {} bytes.", percentTransferred, fileSizeInBytes);
					currentPercentage = percentTransferred;
				}
			}
		});
		
		Upload upload = tm.upload(putObjectRequest);
		if (upload!=null) {
			upload.waitForCompletion();				
		} else {
			logger.error("Did not get upload detail from S3 for asset with key " + key);
			throw new TranscodeException("Did not get upload detail from S3 for asset with key " + key);
		}
	} catch (AmazonClientException | InterruptedException e) {
		throw new TranscodeException(e.getMessage());			
	}
}
 
开发者ID:TimShi,项目名称:s3_video,代码行数:43,代码来源:AWSAdapter.java


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