use of com.aliyun.oss.model.StorageClass in project aliyun-oss-java-sdk by aliyun.
the class ArchiveTest method testNormalRestoreObject.
@Ignore
public void testNormalRestoreObject() {
String bucketName = "restore-object-test-bucket";
String key = "normal-restore-object.txt";
String filePath = null;
try {
// create archive bucket
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setStorageClass(StorageClass.Archive);
ossClient.createBucket(createBucketRequest);
// put archive object
filePath = genFixedLengthFile(1024);
ossClient.putObject(bucketName, key, new File(filePath));
ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, key);
// check whether the object is archive class
StorageClass storageClass = objectMetadata.getObjectStorageClass();
if (storageClass == StorageClass.Archive) {
// restore object
ossClient.restoreObject(bucketName, key);
// wait for restore completed
do {
Thread.sleep(1000);
objectMetadata = ossClient.getObjectMetadata(bucketName, key);
System.out.println("x-oss-restore:" + objectMetadata.getObjectRawRestore());
} while (!objectMetadata.isRestoreCompleted());
}
// get restored object
OSSObject ossObject = ossClient.getObject(bucketName, key);
ossObject.getObjectContent().close();
// restore repeatedly
ossClient.restoreObject(bucketName, key);
// delete object
ossClient.deleteObject(bucketName, key);
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
removeFile(filePath);
ossClient.deleteBucket(bucketName);
}
}
Aggregations