use of com.qcloud.cos.model.Bucket in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method createBucket.
private static void createBucket() throws Exception {
try {
// 避免有查询缓存,导致创建bucket失败
Thread.sleep(5000L);
String bucketName = bucket;
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
Bucket createdBucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, createdBucket.getName());
Thread.sleep(5000L);
assertTrue(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.Bucket in project cos-java-sdk-v5 by tencentyun.
the class GetServiceTest method testGetServiceForNullRegion.
@Test
public void testGetServiceForNullRegion() {
if (!judgeUserInfoValid()) {
return;
}
Region oldRegion = clientConfig.getRegion();
clientConfig.setRegion(null);
try {
List<Bucket> buckets = cosclient.listBuckets();
for (Bucket bucketElement : buckets) {
if (bucketElement.getName().equals(bucket)) {
assertEquals(oldRegion.getRegionName(), bucketElement.getLocation());
return;
}
}
fail("GetService result not contain bucket: " + bucket);
} finally {
clientConfig.setRegion(oldRegion);
}
}
use of com.qcloud.cos.model.Bucket in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicRead.
@Test
public void testCreateDeleteBucketPublicRead() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pubr-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
cosclient.headBucket(new HeadBucketRequest(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.Bucket in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicReadWrite.
@Test
public void testCreateDeleteBucketPublicReadWrite() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pubrw-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicReadWrite);
AccessControlList accessControlList = new AccessControlList();
Grantee grantee = new UinGrantee("730123456");
accessControlList.grantPermission(grantee, Permission.Write);
createBucketRequest.setAccessControlList(accessControlList);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
assertTrue(cosclient.doesBucketExist(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.Bucket in project cos-java-sdk-v5 by tencentyun.
the class BucketDemo method ListBuckets.
public static void ListBuckets() {
// 1 初始化用户身份信息(appid, secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "****************************");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
List<Bucket> buckets = cosclient.listBuckets();
for (Bucket bucket : buckets) {
System.out.println(bucket.getName());
System.out.println(bucket.getLocation());
System.out.println(bucket.getOwner());
System.out.println(bucket.getType());
System.out.println(bucket.getBucketType());
}
}
Aggregations