import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosException;
import com.volcengine.tos.model.bucket.HeadBucketV2Input;
import com.volcengine.tos.model.bucket.HeadBucketV2Output;
public class HeadBucketExample extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = "your access key";
String secretKey = "your secret key";
String securityToken = "your security token";
String bucketName = "your bucket name";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey, securityToken);
Thread tosThread = new Thread(new Runnable() {
HeadBucketV2Input input = new HeadBucketV2Input().setBucket(bucketName);
HeadBucketV2Output output = tos.headBucket(input);
Log.i("headBucket", "bucket's region is " + output.getRegion());
Log.i("headBucket", "bucket's storage class is " + output.getStorageClass());
} catch (TosException e) {
if (e.getStatusCode() == 404) {
Log.e("TosException", "headBucket failed, the bucket is not found.");
Log.e("TosException", "headBucket failed.");