当前位置: 首页>>代码示例>>Java>>正文


Java OSSClient.doesBucketExist方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:21,代码来源:AliyunossProvider.java

示例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();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:23,代码来源:TestOSSService.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:19,代码来源:BucketService.java

示例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);
	}
}
 
开发者ID:lemon-china,项目名称:lemon-fileservice,代码行数:15,代码来源:FileUploadService.java


注:本文中的com.aliyun.oss.OSSClient.doesBucketExist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。