本文整理汇总了Java中com.aliyun.oss.OSSClient.doesBucketExist方法的典型用法代码示例。如果您正苦于以下问题:Java OSSClient.doesBucketExist方法的具体用法?Java OSSClient.doesBucketExist怎么用?Java OSSClient.doesBucketExist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.aliyun.oss.OSSClient
的用法示例。
在下文中一共展示了OSSClient.doesBucketExist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AliyunossProvider
import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
public AliyunossProvider(String urlprefix,String endpoint, String bucketName, String accessKey, String secretKey,boolean isPrivate) {
Validate.notBlank(endpoint, "[endpoint] not defined");
Validate.notBlank(bucketName, "[bucketName] not defined");
Validate.notBlank(accessKey, "[accessKey] not defined");
Validate.notBlank(secretKey, "[secretKey] not defined");
Validate.notBlank(urlprefix, "[urlprefix] not defined");
ossClient = new OSSClient(endpoint, accessKey, secretKey);
this.bucketName = bucketName;
this.urlprefix = urlprefix.endsWith("/") ? urlprefix : (urlprefix + "/");
this.isPrivate = isPrivate;
if (!ossClient.doesBucketExist(bucketName)) {
System.out.println("Creating bucket " + bucketName + "\n");
ossClient.createBucket(bucketName);
CreateBucketRequest createBucketRequest= new CreateBucketRequest(bucketName);
createBucketRequest.setCannedACL(isPrivate ? CannedAccessControlList.Private : CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest);
}
}
示例2: test
import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
@Test
public void test() throws OSSException, ClientException, IOException {
OSSClient client = new OSSClient("oss-cn-hangzhou.aliyuncs.com", "", "", "");
// BucketInfo info = client.getBucketInfo("edrmry");
boolean exists = client.doesBucketExist("edrmry");
System.out.println(exists);
// System.out.println(client.listBuckets().size());
// client.createBucket("dzh1");
PutObjectResult r = client.putObject("edrmry", "dzh1.jpg", new FileInputStream("/Users/dzh/Pictures/8.pic.jpg"));
System.out.println(r.getETag());
OSSObject o = client.getObject("edrmry", "dzh1");
InputStream is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream("/Users/dzh/Pictures/8.pic.2.jpg");
int len = 0;
byte[] buf = new byte[32];
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
fos.close();
}
示例3: doesBucketExist
import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
/**
* 判断Bucket是否存在<br>.
*
* @param client client
* @param bucketName bucketName
* @return boolean
*/
public static boolean doesBucketExist(OSSClient client, String bucketName) {
// 获取Bucket的存在信息
boolean exists = client.doesBucketExist(bucketName);
// 输出结果
if (exists) {
logger.debug("Bucket: " + bucketName + " is exists");
} else {
logger.debug("Bucket: " + bucketName + " is not exists");
}
return exists;
}
示例4: createBucket
import com.aliyun.oss.OSSClient; //导入方法依赖的package包/类
/**
* 创建bucket,阿里设定最多10个bucketName
* @param bucketName bucket名称
* @param isPublic 是否可以公开访问
*/
public void createBucket(OSSClient ossClient, String bucketName, Boolean isPublic){
boolean hasExists = ossClient.doesBucketExist(bucketName);
if (!hasExists) {
// 新建一个Bucket
ossClient.createBucket(bucketName);
// 设置操作权限对外公开
ossClient.setBucketAcl(bucketName, isPublic? CannedAccessControlList.PublicRead: CannedAccessControlList.Private);
}
}