import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosClientException;
import com.volcengine.tos.TosServerException;
import com.volcengine.tos.comm.common.ACLType;
import com.volcengine.tos.comm.common.StorageClassType;
import com.volcengine.tos.model.bucket.CreateBucketV2Input;
import com.volcengine.tos.model.bucket.CreateBucketV2Output;
public class CreateDirectoryBucketExample {
public static void main(String[] args) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = System.getenv("TOS_ACCESS_KEY");
String secretKey = System.getenv("TOS_SECRET_KEY");
String bucketName = "your bucket name";
ACLType aclType = ACLType.ACL_PRIVATE;
StorageClassType storageClassType = StorageClassType.STORAGE_CLASS_STANDARD;
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);
CreateBucketV2Input input = new CreateBucketV2Input().setBucket(bucketName)
.setAcl(aclType).setStorageClass(storageClassType);
CreateBucketV2Output output = tos.createBucket(input);
System.out.println("bucket created: " + output.getLocation());
} catch (TosClientException e) {
System.out.println("createBucket failed");
System.out.println("Message: " + e.getMessage());
if (e.getCause() != null) {
e.getCause().printStackTrace();
} catch (TosServerException e) {
System.out.println("createBucket failed");
System.out.println("StatusCode: " + e.getStatusCode());
System.out.println("Code: " + e.getCode());
System.out.println("Message: " + e.getMessage());
System.out.println("RequestID: " + e.getRequestID());
System.out.println("createBucket failed");
System.out.println("unexpected exception, message: " + t.getMessage());