赞
踩
设置桶策略,输入桶的名称及策略名称
获取桶策略,如果桶没有被设置过策略,则返回没有策略
删除桶策略
桶存量信息storageInfo,含有对象数和总大小两个信息,通过get()方法获取
桶配额为long型变量,可以对桶的总配额进行设置
存储类型:标准、归档、低频 将storagePolicy型处理,只返回STANDARD、COLD、WARM字符串
代码如下
/* 设置桶策略 */ public void setBucketPolicy(String bucketName,String policy) { ObsClient obsClient = new ObsClient(ak, sk, endPoint); obsClient.setBucketPolicy(bucketName, policy); } /* 获取桶策略 */ public String getBucketPolicy(String bucketName) { try{ String policy = obsClient.getBucketPolicy(bucketName); System.out.println("\t" + policy); return policy; }catch (ObsException e){ return "no policy"; } } /* 删除桶策略 */ public void deleteBucketPolicy(String bucketName){ obsClient.deleteBucketPolicy(bucketName); } /* 获取桶的区域位置 */ public String getlocation(String bucketName){ String location = obsClient.getBucketLocation(bucketName); System.out.println("\t:" + location); return location; } /* 获取桶存量信息 */ public BucketStorageInfo getBucketStorageInfo(String bucketName){ BucketStorageInfo storageInfo = obsClient.getBucketStorageInfo(bucketName); System.out.println("\t" + storageInfo.getObjectNumber()); System.out.println("\t" + storageInfo.getSize()); return storageInfo; } /* 设置桶配额 */ public void setBucketQuota(String bucketName,long size){ BucketQuota quota = new BucketQuota(size); obsClient.setBucketQuota(bucketName, quota); System.out.println("set quota success"); } /* 获取桶配额 */ public long getBucketQuota(String bucketName){ BucketQuota quota = obsClient.getBucketQuota(bucketName); // System.out.println("\t" + quota.getBucketQuota()); return quota.getBucketQuota(); } /* 设置桶存储类型 */ public void setBucketStoragePolicy(String bucketName,int policy){ BucketStoragePolicyConfiguration storgePolicy = new BucketStoragePolicyConfiguration(); switch (policy){ case 0:{ storgePolicy.setBucketStorageClass(StorageClassEnum.STANDARD); } case 1:{ storgePolicy.setBucketStorageClass(StorageClassEnum.WARM); } case 2:{ storgePolicy.setBucketStorageClass(StorageClassEnum.COLD); } } obsClient.setBucketStoragePolicy(bucketName, storgePolicy); } /* 获取桶存储类型 */ public String getBucketStorageClass(String bucketName){ BucketStoragePolicyConfiguration storagePolicy = obsClient.getBucketStoragePolicy(bucketName); // System.out.println("\t" + storagePolicy.getBucketStorageClass()); return storagePolicy.getBucketStorageClass().toString(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。