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


Java S3Object.close方法代码示例

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


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

示例1: getInventoryManifest

import com.amazonaws.services.s3.model.S3Object; //导入方法依赖的package包/类
/**
 * Check if the MD5s of manifest.json and manifest.checksum equal
 * if so, pull out the manifest file and map it into a POJO
 * @return inventoryManifestStorage InventoryManifest, which stores all the elements of the manifest.json file
 */
public InventoryManifest getInventoryManifest() throws Exception {
    // Get manifest.json and transfer it to String
    GetObjectRequest requestJson = new GetObjectRequest(bucketName, bucketKeyJson);
    S3Object jsonObject = s3Client.getObject(requestJson);
    String jsonFile = inputStreamToString(jsonObject.getObjectContent());
    jsonObject.close();

    // Get manifest.checksum and transfer it to String with no whitespace
    GetObjectRequest requestChecksum = new GetObjectRequest(bucketName, bucketKeyChecksum);
    S3Object checksumObject = s3Client.getObject(requestChecksum);
    String expectedChecksum = inputStreamToString(checksumObject.getObjectContent())
            .replaceAll("\\s","");
    checksumObject.close();

    // Compare manifest.json and manifest.checksum's MD5 value
    String actualChecksum = DigestUtils.md5Hex(jsonFile);
    if (!actualChecksum.equals(expectedChecksum)) {
        throw new ChecksumMismatchException (expectedChecksum, actualChecksum);
    }

    return mapper.readValue(jsonFile, InventoryManifest.class);
}
 
开发者ID:awslabs,项目名称:s3-inventory-usage-examples,代码行数:28,代码来源:InventoryManifestRetriever.java

示例2: shouldUploadAndDownloadObject

import com.amazonaws.services.s3.model.S3Object; //导入方法依赖的package包/类
/**
 * Stores a file in a previously created bucket. Downloads the file again and compares checksums
 *
 * @throws Exception if FileStreams can not be read
 */
@Test
public void shouldUploadAndDownloadObject() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);
  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, uploadFile.getName(), uploadFile));

  final S3Object s3Object = s3Client.getObject(BUCKET_NAME, uploadFile.getName());

  final InputStream uploadFileIS = new FileInputStream(uploadFile);
  final String uploadHash = HashUtil.getDigest(uploadFileIS);
  final String downloadedHash = HashUtil.getDigest(s3Object.getObjectContent());
  uploadFileIS.close();
  s3Object.close();

  assertThat("Up- and downloaded Files should have equal Hashes", uploadHash,
      is(equalTo(downloadedHash)));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:24,代码来源:AmazonClientUploadIT.java

示例3: shouldUploadAndDownloadObject

import com.amazonaws.services.s3.model.S3Object; //导入方法依赖的package包/类
/**
 * Stores a file in a previously created bucket. Downloads the file again and compares checksums.
 *
 * @throws Exception if FileStreams can not be read
 */
@Test
public void shouldUploadAndDownloadObject() throws Exception {
  final File uploadFile = new File(UPLOAD_FILE_NAME);

  s3Client.createBucket(BUCKET_NAME);
  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, uploadFile.getName(), uploadFile));

  final S3Object s3Object = s3Client.getObject(BUCKET_NAME, uploadFile.getName());

  final InputStream uploadFileIS = new FileInputStream(uploadFile);
  final String uploadHash = HashUtil.getDigest(uploadFileIS);
  final String downloadedHash = HashUtil.getDigest(s3Object.getObjectContent());
  uploadFileIS.close();
  s3Object.close();

  assertThat("Up- and downloaded Files should have equal Hashes", uploadHash,
      is(equalTo(downloadedHash)));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:24,代码来源:S3MockRuleTest.java

示例4: shouldUploadAndDownloadStream

import com.amazonaws.services.s3.model.S3Object; //导入方法依赖的package包/类
/**
 * Stores a file in a previously created bucket. Downloads the file again and compares checksums
 *
 * @throws Exception if FileStreams can not be read
 */
@Test
public void shouldUploadAndDownloadStream() throws Exception {
  s3Client.createBucket(BUCKET_NAME);
  final String resourceId = UUID.randomUUID().toString();

  final byte[] resource = new byte[] {1, 2, 3, 4, 5};
  final ByteArrayInputStream bais = new ByteArrayInputStream(resource);

  final ObjectMetadata objectMetadata = new ObjectMetadata();
  objectMetadata.setContentLength(resource.length);
  final PutObjectRequest putObjectRequest =
      new PutObjectRequest(BUCKET_NAME, resourceId, bais, objectMetadata);

  final TransferManager tm = createDefaultTransferManager();
  final Upload upload = tm.upload(putObjectRequest);

  upload.waitForUploadResult();

  final S3Object s3Object = s3Client.getObject(BUCKET_NAME, resourceId);

  final String uploadHash = HashUtil.getDigest(new ByteArrayInputStream(resource));
  final String downloadedHash = HashUtil.getDigest(s3Object.getObjectContent());
  s3Object.close();

  assertThat("Up- and downloaded Files should have equal Hashes", uploadHash,
      is(equalTo(downloadedHash)));
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:33,代码来源:AmazonClientUploadIT.java


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