Last update:2025-08-18 15:54:14
You can use WosClient.listBuckets to list all buckets. The following example shows how to retrieve the list of buckets:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create WosClient instance
WosClient wosClient = new WosClient(ak, sk, endPoint, regionName);
// List buckets
List<WosBucket> buckets = wosClient.listBuckets();
for (WosBucket bucket : buckets) {
System.out.println("BucketName: " + bucket.getBucketName());
System.out.println("CreationDate: " + bucket.getCreationDate());
System.out.println("Endpoint: " + bucket.getEndpoint());
}
Note: The returned bucket list is sorted lexicographically (dictionary order) by bucket name.
You can use WosClient.headBucket to check whether a specified bucket exists. The following example demonstrates how to check for a bucket’s existence:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create WosClient instance
WosClient wosClient = new WosClient(ak, sk, endPoint, regionName);
boolean exists = wosClient.headBucket("bucketname");
WOS allows you to configure lifecycle rules for buckets to automate storage class transitions and the deletion of expired objects. This helps you make efficient use of storage and optimize your bucket management.
You can define multiple rules for objects with different prefixes. Each rule includes the following elements:
You can set lifecycle rules for a bucket using WosClient.setBucketLifecycleConfiguration.
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create WosClient instance
WosClient wosClient = new WosClient(ak, sk, endPoint, regionName);
final String ruleId = "delete obsoleted files";
final String matchPrefix = "obsoleted/";
LifecycleConfiguration lifecycleConfig = new LifecycleConfiguration();
LifecycleConfiguration.Rule rule = lifecycleConfig.new Rule();
rule.setEnabled(true);
rule.setId(ruleId);
rule.setPrefix(matchPrefix);
LifecycleConfiguration.Expiration expiration = lifecycleConfig.new Expiration();
expiration.setDays(10);
rule.setExpiration(expiration);
lifecycleConfig.addRule(rule);
System.out.println("Setting bucket lifecycle\n");
HeaderResponse headerResponse = wosClient.setBucketLifecycleConfiguration(bucketName, lifecycleConfig);
System.out.println(headerResponse);
You can retrieve lifecycle rules configured for a bucket using WosClient.getBucketLifecycle. The following example demonstrates how to view lifecycle rules:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create WosClient instance
WosClient wosClient = new WosClient(ak, sk, endPoint, regionName);
LifecycleConfiguration config = wosClient.getBucketLifecycle("bucketname");
for (Rule rule : config.getRules()) {
System.out.println(rule.getId());
System.out.println(rule.getPrefix());
for (Transition transition : rule.getTransitions()) {
System.out.println(transition.getDays());
System.out.println(transition.getStorageClass());
}
System.out.println(rule.getExpiration() != null ? rule.getExpiration().getDays() : "");
}
You can delete all lifecycle rules for a bucket using WosClient.deleteBucketLifecycle. The following example demonstrates how to remove lifecycle rules from a bucket:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create WosClient instance
WosClient wosClient = new WosClient(ak, sk, endPoint, regionName);
wosClient.deleteBucketLifecycle("bucketname");