• 大小: 7.54MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-02
  • 语言: 其他
  • 标签: BOS  

资源简介

百度对象存储BOS的一个测试demo,可以参考我的博客介绍http://blog.csdn.net/boonya/article/details/46330433

资源截图

代码片段和文件信息

package com.boonya.bos.bucket;

import java.util.ArrayList;
import java.util.List;
import com.baidubce.services.bos.BosClient;
import com.baidubce.services.bos.model.BucketSummary;
import com.baidubce.services.bos.model.CannedAccessControlList;
import com.baidubce.services.bos.model.Grant;
import com.baidubce.services.bos.model.Grantee;
import com.baidubce.services.bos.model.Permission;

public class Bucket
{
    /**
     * 创建bucket
     * 
     * @param client
     * @param bucketName
     */
    public void createBucket(BosClient client String bucketName)
    {
// 新建一个Bucket
client.createBucket(bucketName);
    }
    
    /**
     * 获取bucket列表
     * 
     * @param client
     */
    public void listBuckets(BosClient client)
    {
// 获取用户的Bucket列表
List buckets = client.listBuckets().getBuckets();

// 遍历Bucket
for (BucketSummary bucket : buckets)
{
    System.out.println(bucket.getName());
}
    }
    
    /**
     * 判断Bucket是否存在
     * 
     * @param client
     * @param bucketName
     */
    public boolean doesBucketExist(BosClient client String bucketName)
    {

// 获取Bucket的存在信息
boolean exists = client.doesBucketExist(bucketName);

// 输出结果
if (exists)
{
    System.out.println(“Bucket exists“);
} else
{
    System.out.println(“Bucket not exists“);
}
return exists;
    }
    
    /**
     * 删除Bucket
     * 
     * @param client
     * @param bucketName
     */
    public void deleteBucket(BosClient client String bucketName)
    {
// 删除Bucket
client.deleteBucket(bucketName);
    }
    
    /**
     * 设置Bucket的访问权限
     * 
     * @param client
     * @param bucketName
     */
    public void setBucketPrivate(BosClient client String bucketName)
    {
client.setBucketAcl(bucketName CannedAccessControlList.Private);
    }
    
    /**
     * 设置指定用户对Bucket的访问权限
     * 
     * @param client
     */
    public void SetBucketAclFromBody(BosClient client)
    {
List grants = new ArrayList(); 
List grantee = new ArrayList();
List permission = new ArrayList();

// 授权给特定用户
grantee.add(new Grantee(“UserId_1“));
grantee.add(new Grantee(“UserId_2“));
// 授权给Everyone
grantee.add(new Grantee(“*“));

// 设置权限
//Permission中的权限设置包含三个值:READ、WRITE、FULL_CONTROL
permission.add(Permission.READ);
permission.add(Permission.WRITE);

grants.add(new Grant().withGrantee(grantee).withPermission(permission));
//client.setBucketAcl(“bucketName“ grants);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-08-18 15:25  BOS-demo\
     文件        2713  2015-06-02 12:59  BOS-demo\.classpath
     文件        1333  2015-06-02 13:02  BOS-demo\.project
     目录           0  2015-08-18 15:25  BOS-demo\.settings\
     文件         522  2015-06-02 12:57  BOS-demo\.settings\.jsdtscope
     文件         364  2015-06-02 12:57  BOS-demo\.settings\org.eclipse.jdt.core.prefs
     文件         483  2015-06-02 12:57  BOS-demo\.settings\org.eclipse.wst.common.component
     文件         305  2015-06-02 12:57  BOS-demo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2015-06-02 12:57  BOS-demo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2015-06-02 12:57  BOS-demo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\meta-INF\
     文件          39  2015-06-02 12:57  BOS-demo\WebRoot\meta-INF\MANIFEST.MF
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\bucket\
     文件        3429  2015-08-18 14:41  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\bucket\Bucket.class
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\object\
     文件        8191  2015-08-18 14:41  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\object\object.class
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\samle\
     文件        1621  2015-08-18 14:41  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\samle\AntornizationSample.class
     文件        2469  2015-08-18 14:41  BOS-demo\WebRoot\WEB-INF\classes\com\boonya\bos\samle\Sample.class
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\lib\
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\lib\bce-java-sdk-0.8.4\
     文件       10173  2015-06-02 12:58  BOS-demo\WebRoot\WEB-INF\lib\bce-java-sdk-0.8.4\LICENSE.txt
     目录           0  2015-08-18 15:25  BOS-demo\WebRoot\WEB-INF\lib\bce-java-sdk-0.8.4\lib\
     文件     1365177  2015-06-02 12:58  BOS-demo\WebRoot\WEB-INF\lib\bce-java-sdk-0.8.4\lib\bce-java-sdk-0.8.4-javadoc.jar
     文件      279675  2015-06-02 12:58  BOS-demo\WebRoot\WEB-INF\lib\bce-java-sdk-0.8.4\lib\bce-java-sdk-0.8.4-sources.jar
............此处省略32个文件信息

评论

共有 条评论