Search in sources :

Example 1 with StorageClass

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);
    }
}
Also used : OSSObject(com.aliyun.oss.model.OSSObject) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest) StorageClass(com.aliyun.oss.model.StorageClass) TestUtils.genFixedLengthFile(com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile) TestUtils.removeFile(com.aliyun.oss.integrationtests.TestUtils.removeFile) File(java.io.File) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSSException(com.aliyun.oss.OSSException) Ignore(org.junit.Ignore)

Aggregations

OSSException (com.aliyun.oss.OSSException)1 TestUtils.genFixedLengthFile (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile)1 TestUtils.removeFile (com.aliyun.oss.integrationtests.TestUtils.removeFile)1 CreateBucketRequest (com.aliyun.oss.model.CreateBucketRequest)1 OSSObject (com.aliyun.oss.model.OSSObject)1 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)1 StorageClass (com.aliyun.oss.model.StorageClass)1 File (java.io.File)1 Ignore (org.junit.Ignore)1