本文整理汇总了Java中com.amazonaws.services.s3.AmazonS3.getObjectMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3.getObjectMetadata方法的具体用法?Java AmazonS3.getObjectMetadata怎么用?Java AmazonS3.getObjectMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.getObjectMetadata方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
ObjectMetadata metadata = s3Client.getObjectMetadata(
new GetObjectMetadataRequest(bucket, objectKey));
try {
Date expirationTime = metadata.getExpirationTime();
if (expirationTime != null) {
this.writeOutput("expirationTime", metadata.getExpirationTime().getTime());
} else {
this.writeOutput("expirationTime", null);
}
this.writeOutput("lastModified", metadata.getLastModified().getTime());
this.writeOutput("userMetadata", metadata.getUserMetadata());
this.writeOutput("size", metadata.getContentLength());
this.writeOutput("storageClass", metadata.getStorageClass());
this.writeOutput("versionId", metadata.getVersionId());
} catch (Exception ex) {
throw new RuntimeException(String.format(
"Failed to get object metadata for object key %s in bucket %s",
objectKey,
bucket), ex);
}
}
示例2: itDoesntCount404AsFailure
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Test
public void itDoesntCount404AsFailure() throws InterruptedException {
AmazonS3 s3 = HystrixS3Decorator.decorate(new MissingS3Client());
for (int i = 0; i < 100; i++ ) {
try {
s3.getObjectMetadata("test-bucket", "test-key");
} catch (AmazonServiceException e) {
assertThat(e.getStatusCode()).isEqualTo(404);
}
Thread.sleep(50);
}
}
示例3: itDoesntCount403AsFailure
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Test
public void itDoesntCount403AsFailure() throws InterruptedException {
AmazonS3 s3 = HystrixS3Decorator.decorate(new NotAuthedS3Client());
for (int i = 0; i < 100; i++ ) {
try {
s3.getObjectMetadata("test-bucket", "test-key");
} catch (AmazonServiceException e) {
assertThat(e.getStatusCode()).isEqualTo(403);
}
Thread.sleep(50);
}
}
示例4: itDoesntCount404AsFailure
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Test
public void itDoesntCount404AsFailure() throws InterruptedException {
AmazonS3 s3 = FailsafeS3Decorator.decorate(new MissingS3Client());
for (int i = 0; i < 100; i++ ) {
try {
s3.getObjectMetadata("test-bucket", "test-key");
} catch (AmazonServiceException e) {
assertThat(e.getStatusCode()).isEqualTo(404);
}
Thread.sleep(50);
}
}
示例5: itDoesntCount403AsFailure
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
@Test
public void itDoesntCount403AsFailure() throws InterruptedException {
AmazonS3 s3 = FailsafeS3Decorator.decorate(new NotAuthedS3Client());
for (int i = 0; i < 100; i++ ) {
try {
s3.getObjectMetadata("test-bucket", "test-key");
} catch (AmazonServiceException e) {
assertThat(e.getStatusCode()).isEqualTo(403);
}
Thread.sleep(50);
}
}
示例6: S3RangedReadObjectChannel
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
public S3RangedReadObjectChannel(String key, String bucket, AmazonS3 s3) {
super(key, bucket, s3);
metadata = s3.getObjectMetadata(bucket, key);
size = metadata.getContentLength();
}
示例7: getPartCount
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
* Returns the part count of the object represented by the getObjectRequest.
*
* @param getObjectRequest
* The request to check.
* @param s3
* The Amazon s3 client.
*
* @return The number of parts in the object if it is multipart object, otherwise returns null.
*/
public static Integer getPartCount(GetObjectRequest getObjectRequest, AmazonS3 s3) {
ValidationUtils.assertNotNull(s3, "S3 client");
ValidationUtils.assertNotNull(getObjectRequest, "GetObjectRequest");
ObjectMetadata metadata = s3.getObjectMetadata(new GetObjectMetadataRequest(getObjectRequest.getBucketName(), getObjectRequest.getKey(), getObjectRequest.getVersionId())
.withSSECustomerKey(getObjectRequest.getSSECustomerKey())
.withPartNumber(1));
return metadata.getPartCount();
}
示例8: getLastByteInPart
import com.amazonaws.services.s3.AmazonS3; //导入方法依赖的package包/类
/**
* Returns the last byte number in a part of an object.
*
* @param s3
* The Amazon s3 client.
* @param getObjectRequest
* The request to check.
* @param partNumber
* The part in which we need the last byte number.
* @return
* The last byte number in the part.
*/
public static long getLastByteInPart(AmazonS3 s3, GetObjectRequest getObjectRequest, Integer partNumber) {
ValidationUtils.assertNotNull(s3, "S3 client");
ValidationUtils.assertNotNull(getObjectRequest, "GetObjectRequest");
ValidationUtils.assertNotNull(partNumber, "partNumber");
ObjectMetadata metadata = s3.getObjectMetadata(new GetObjectMetadataRequest(getObjectRequest.getBucketName(), getObjectRequest.getKey(), getObjectRequest.getVersionId())
.withSSECustomerKey(getObjectRequest.getSSECustomerKey())
.withPartNumber(partNumber));
return metadata.getContentRange()[1];
}