Archive direct read (Java SDK V2)
Manage archive direct read configurations by calling the PutBucketArchiveDirectRead and GetBucketArchiveDirectRead operations with OSS Java SDK V2.
Prerequisites
OSS Java SDK V2 is installed. If you use Maven, add the dependency
com.aliyun:alibabacloud-oss-v2.Access credentials are configured by using environment variables. The sample code in this topic uses
EnvironmentVariableCredentialsProviderto read credentials from theOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables.
Permissions
By default, an Alibaba Cloud account has all permissions, but RAM users and RAM roles under the account have none. The Alibaba Cloud account or an account administrator must grant the permissions required to perform the operations.
API | Action | Description |
PutBucketArchiveDirectRead |
| Set or query the archive direct read configuration of a bucket. |
Sample code
import com.aliyun.sdk.service.oss2.OSSClient;
import com.aliyun.sdk.service.oss2.OSSClientBuilder;
import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.models.*;
public class ArchiveDirectReadSample {
public static void main(String[] args) throws Exception {
String region = "cn-hangzhou";
String bucket = "examplebucket";
CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
OSSClientBuilder clientBuilder = OSSClient.newBuilder()
.credentialsProvider(provider)
.region(region);
try (OSSClient client = clientBuilder.build()) {
// Enable archive direct read
ArchiveDirectReadConfiguration config = ArchiveDirectReadConfiguration.newBuilder()
.enabled(true)
.build();
PutBucketArchiveDirectReadResult putResult = client.putBucketArchiveDirectRead(
PutBucketArchiveDirectReadRequest.newBuilder()
.bucket(bucket)
.archiveDirectReadConfiguration(config)
.build());
System.out.printf("PutBucketArchiveDirectRead status code:%d%n", putResult.statusCode());
// Query the archive direct read configuration
GetBucketArchiveDirectReadResult getResult = client.getBucketArchiveDirectRead(
GetBucketArchiveDirectReadRequest.newBuilder().bucket(bucket).build());
System.out.printf("Archive direct read enabled: %s%n",
getResult.archiveDirectReadConfiguration().enabled());
} catch (Exception e) {
System.out.printf("error:%n%s", e);
}
}
}
References
For the synchronous sample code, see PutBucketArchiveDirectRead.java.
For the asynchronous sample code, see PutBucketArchiveDirectReadAsync.java.
For the synchronous sample code, see GetBucketArchiveDirectRead.java.
For the asynchronous sample code, see GetBucketArchiveDirectReadAsync.java.