本文整理汇总了Java中com.amazonaws.services.s3.model.HeadBucketRequest类的典型用法代码示例。如果您正苦于以下问题:Java HeadBucketRequest类的具体用法?Java HeadBucketRequest怎么用?Java HeadBucketRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HeadBucketRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了HeadBucketRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doesBucketExist
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Override
public boolean doesBucketExist(String bucketName)
throws SdkClientException, AmazonServiceException {
try {
headBucket(new HeadBucketRequest(bucketName));
return true;
} catch (AmazonServiceException ase) {
// A redirect error or a forbidden error means the bucket exists. So
// returning true.
if ((ase.getStatusCode() == Constants.BUCKET_REDIRECT_STATUS_CODE)
|| (ase.getStatusCode() == Constants.BUCKET_ACCESS_FORBIDDEN_STATUS_CODE)) {
return true;
}
if (ase.getStatusCode() == Constants.NO_SUCH_BUCKET_STATUS_CODE) {
return false;
}
throw ase;
}
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:22,代码来源:AmazonS3Client.java
示例2: getBucketRegionViaHeadRequest
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
/**
* Retrieves the region of the bucket by making a HeadBucket request to us-west-1 region.
*
* Currently S3 doesn't return region in a HEAD Bucket request if the bucket
* owner has enabled bucket to accept only SigV4 requests via bucket
* policies.
*/
private String getBucketRegionViaHeadRequest(String bucketName) {
String bucketRegion = null;
try {
Request<HeadBucketRequest> request = createRequest(bucketName, null,
new HeadBucketRequest(bucketName), HttpMethodName.HEAD);
HeadBucketResult result = invoke(request, new HeadBucketResultHandler(), bucketName, null, true);
bucketRegion = result.getBucketRegion();
} catch (AmazonS3Exception exception) {
if (exception.getAdditionalDetails() != null) {
bucketRegion = exception.getAdditionalDetails().get(
Headers.S3_BUCKET_REGION);
}
}
if (bucketRegion == null && log.isDebugEnabled()) {
log.debug("Not able to derive region of the " + bucketName + " from the HEAD Bucket requests.");
}
return bucketRegion;
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:30,代码来源:AmazonS3Client.java
示例3: removeBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Test
public void removeBucket() throws Exception {
String bucketName = "testremovebkbk" + UUID.randomUUID().toString();
// remove bucket not exist
Thread.sleep(3000);
RGW_ADMIN.removeBucket(bucketName);
testWithAUser(
v -> {
String userId = "testremovebk" + UUID.randomUUID().toString();
User response = RGW_ADMIN.createUser(userId);
AmazonS3 s3 =
createS3(
response.getS3Credentials().get(0).getAccessKey(),
response.getS3Credentials().get(0).getSecretKey());
s3.createBucket(bucketName);
ByteArrayInputStream input = new ByteArrayInputStream("Hello World!".getBytes());
s3.putObject(bucketName, "hello.txt", input, new ObjectMetadata());
RGW_ADMIN.removeBucket(bucketName);
try {
s3.headBucket(new HeadBucketRequest(bucketName));
fail();
} catch (Exception e) {
assertTrue("Not Found".equals(((AmazonS3Exception) e).getErrorMessage()));
}
});
}
开发者ID:twonote,项目名称:radosgw-admin4j,代码行数:33,代码来源:RgwAdminImplTest.java
示例4: unlinkBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Test
public void unlinkBucket() throws Exception {
testWithAUser(
(v) -> {
String userId = v.getUserId();
AmazonS3 s3 =
createS3(
v.getS3Credentials().get(0).getAccessKey(),
v.getS3Credentials().get(0).getSecretKey());
String bucketName = userId.toLowerCase();
// not exist
RGW_ADMIN.unlinkBucket(bucketName, userId);
s3.createBucket(bucketName);
// basic
RGW_ADMIN.unlinkBucket(bucketName, userId);
assertEquals(0, s3.listBuckets().size());
// head is ok...
s3.headBucket(new HeadBucketRequest(bucketName));
// again
RGW_ADMIN.unlinkBucket(bucketName, userId);
});
}
开发者ID:twonote,项目名称:radosgw-admin4j,代码行数:28,代码来源:RgwAdminImplTest.java
示例5: headBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Override
public HeadBucketResult headBucket(HeadBucketRequest headBucketRequest)
throws SdkClientException, AmazonServiceException {
headBucketRequest = beforeClientExecution(headBucketRequest);
String bucketName = headBucketRequest.getBucketName();
rejectNull(bucketName,
"The bucketName parameter must be specified.");
Request<HeadBucketRequest> request = createRequest(bucketName, null,
headBucketRequest, HttpMethodName.HEAD);
return invoke(request, new HeadBucketResultHandler(), bucketName, null);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:AmazonS3Client.java
示例6: testContainerExists
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Test
public void testContainerExists() throws Exception {
client.headBucket(new HeadBucketRequest(containerName));
try {
client.headBucket(new HeadBucketRequest(
createRandomContainerName()));
Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
} catch (AmazonS3Exception e) {
assertThat(e.getErrorCode()).isEqualTo("404 Not Found");
}
}
开发者ID:gaul,项目名称:s3proxy,代码行数:12,代码来源:AwsSdkTest.java
示例7: testContainerDelete
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Test
public void testContainerDelete() throws Exception {
client.headBucket(new HeadBucketRequest(containerName));
client.deleteBucket(containerName);
try {
client.headBucket(new HeadBucketRequest(containerName));
Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
} catch (AmazonS3Exception e) {
assertThat(e.getErrorCode()).isEqualTo("404 Not Found");
}
}
开发者ID:gaul,项目名称:s3proxy,代码行数:12,代码来源:AwsSdkTest.java
示例8: createBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {
client.createBucket(bucketName);
HeadBucketRequest request = new HeadBucketRequest(bucketName);
Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists();
Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler());
future.get(1, TimeUnit.MINUTES);
}
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:11,代码来源:S3Utils.java
示例9: headBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Override
public HeadBucketResult headBucket(HeadBucketRequest headBucketRequest) throws AmazonClientException, AmazonServiceException {
return delegate.headBucket(headBucketRequest);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AmazonS3Wrapper.java
示例10: headBucket
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
@Override
public HeadBucketResult headBucket(HeadBucketRequest headBucketRequest) throws SdkClientException, AmazonServiceException {
return call(() -> getDelegate().headBucket(headBucketRequest));
}
开发者ID:HubSpot,项目名称:S3Decorators,代码行数:5,代码来源:S3Decorator.java
示例11: FindOrCreateWeatherPipeJobDirectory
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
public String FindOrCreateWeatherPipeJobDirectory() {
String bucketLocation = null;
try {
if(!(s3client.doesBucketExist(jobBucketName))) {
// Note that CreateBucketRequest does not specify region. So bucket is
// created in the region specified in the client.
s3client.createBucket(new CreateBucketRequest(
jobBucketName));
} else {
s3client.headBucket(new HeadBucketRequest(jobBucketName));
}
bucketLocation = "s3n://" + jobBucketName + "/";
} catch (AmazonServiceException ase) {
if(ase.getStatusCode() == 403) {
System.out.println("You do not have propper permissions to access " + jobBucketName +
". S3 uses a global name space, please make sure you are using a unique bucket name.");
System.exit(1);
} else {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
}
System.exit(1);
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
System.exit(1);
}
return bucketLocation;
}
开发者ID:stephenlienharrell,项目名称:WeatherPipe,代码行数:47,代码来源:AWSInterface.java
示例12: apply
import com.amazonaws.services.s3.model.HeadBucketRequest; //导入依赖的package包/类
/**
* Makes a call to the operation specified by the waiter by taking the
* corresponding request and returns the corresponding result
*
* @param headBucketRequest
* Corresponding request for the operation
* @return Corresponding result of the operation
*/
@Override
public HeadBucketResult apply(HeadBucketRequest headBucketRequest) {
return client.headBucket(headBucketRequest);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:13,代码来源:HeadBucketFunction.java
注:本文中的com.amazonaws.services.s3.model.HeadBucketRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论