本文整理匯總了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)));
}