本文整理汇总了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);
}
示例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)));
}
示例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)));
}
示例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)));
}