Help Center> Object Storage Service> SDK Reference> Java> Bucket Management> Setting or Obtaining the Storage Class of a Bucket

Setting or Obtaining the Storage Class of a Bucket

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

OBS allows you to set storage classes for buckets. The storage class of an object defaults to be that of its residing bucket. Different storage classes meet different needs for storage performance and costs. There are three types of storage class for buckets, as described in the following table:

Storage Class

Description

Value in OBS Java SDK

OBS Standard

Features low access latency and high throughput and is applicable to storing frequently-accessed (multiple times per month) hotspot or small objects (< 1 MB) requiring quick response.

StorageClassEnum.STANDARD

OBS Infrequent Access

Is applicable to storing semi-frequently accessed (less than 12 times a year) data requiring quick response.

StorageClassEnum.WARM

OBS Archive

Is applicable to archiving rarely-accessed (once a year) data.

StorageClassEnum.COLD

For more information, see Bucket Storage Classes.

The bucket storage class is independent from the storage classes of objects in the bucket. If the object storage class is not set during object upload, the object storage class is the same as that of the bucket. However, if the storage class of the bucket is changed, the storage class of the objects in the bucket does not change accordingly. If the storage class of an object in a bucket is changed, the storage class of the bucket does not change either.

Setting the Storage Class for a Bucket

You can call ObsClient.setBucketStoragePolicy to set the storage class for a bucket. Sample code is as follows:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

// Set the storage class to OBS Infrequent Access.
BucketStoragePolicyConfiguration storagePolicy = new BucketStoragePolicyConfiguration();
storagePolicy.setBucketStorageClass(StorageClassEnum.WARM);
obsClient.setBucketStoragePolicy("bucketname", storagePolicy);

Obtaining the Storage Class of a Bucket

You can call ObsClient.getBucketStoragePolicy to obtain the storage class of a bucket. Sample code is as follows:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

BucketStoragePolicyConfiguration storagePolicy = obsClient.getBucketStoragePolicy("bucketname");
System.out.println("\t" + storagePolicy.getBucketStorageClass());