Search in sources :

Example 1 with SimplifiedObjectMeta

use of com.aliyun.oss.model.SimplifiedObjectMeta in project aliyun-oss-java-sdk by aliyun.

the class GetRequestIdTest method testNormalGetRequestId.

@Test
public void testNormalGetRequestId() {
    final String key = "normal-get-request-id";
    final long inputStreamLength = 1024;
    final int requestIdLength = "572BF2F2207FB3397648E9F1".length();
    try {
        // put object
        PutObjectResult putObjectResult = ossClient.putObject(bucketName, key, genFixedLengthInputStream(inputStreamLength));
        Assert.assertEquals(putObjectResult.getRequestId().length(), requestIdLength);
        // get object
        OSSObject ossObject = ossClient.getObject(bucketName, key);
        ossObject.getObjectContent().close();
        Assert.assertEquals(ossObject.getRequestId().length(), requestIdLength);
        File file = new File("tmp");
        GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
        ObjectMetadata objectMeta = ossClient.getObject(getObjectRequest, file);
        Assert.assertEquals(objectMeta.getRequestId().length(), requestIdLength);
        // delete object
        ossClient.deleteObject(bucketName, key);
        // append object
        AppendObjectRequest appendObjectRequest = new AppendObjectRequest(bucketName, key, file);
        appendObjectRequest.setPosition(0L);
        AppendObjectResult appendObjectResult = ossClient.appendObject(appendObjectRequest);
        Assert.assertEquals(appendObjectResult.getRequestId().length(), requestIdLength);
        // getSimplifiedObjectMeta
        SimplifiedObjectMeta simplifiedObjectMeta = ossClient.getSimplifiedObjectMeta(bucketName, key);
        Assert.assertEquals(simplifiedObjectMeta.getRequestId().length(), requestIdLength);
        // getObjectMetadata
        ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, key);
        Assert.assertEquals(objectMetadata.getRequestId().length(), requestIdLength);
        // delete objects
        DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
        ArrayList<String> keys = new ArrayList<String>();
        keys.add(key);
        deleteObjectsRequest.setKeys(keys);
        DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(deleteObjectsRequest);
        Assert.assertEquals(deleteObjectsResult.getRequestId().length(), requestIdLength);
        // initiate multipart upload
        InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(bucketName, key);
        InitiateMultipartUploadResult initiateMultipartUploadResult = ossClient.initiateMultipartUpload(initiateMultipartUploadRequest);
        Assert.assertEquals(initiateMultipartUploadResult.getRequestId().length(), requestIdLength);
        // upload part
        UploadPartRequest uploadPartRequest = new UploadPartRequest(bucketName, key, initiateMultipartUploadResult.getUploadId(), 1, new FileInputStream(file), inputStreamLength);
        UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
        Assert.assertEquals(uploadPartResult.getRequestId().length(), requestIdLength);
        // complete multipart upload
        List<PartETag> partETags = new ArrayList<PartETag>();
        partETags.add(new PartETag(1, uploadPartResult.getETag()));
        CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, initiateMultipartUploadResult.getUploadId(), partETags);
        CompleteMultipartUploadResult completeMultipartUploadResult = ossClient.completeMultipartUpload(completeMultipartUploadRequest);
        Assert.assertEquals(completeMultipartUploadResult.getRequestId().length(), requestIdLength);
        // copy object
        CopyObjectResult CopyObjectResult = ossClient.copyObject(bucketName, key, bucketName, key);
        Assert.assertEquals(CopyObjectResult.getRequestId().length(), requestIdLength);
        // initiate multipart copy
        InitiateMultipartUploadRequest initiateMultipartCopyRequest = new InitiateMultipartUploadRequest(bucketName, key);
        InitiateMultipartUploadResult initiateMultipartCopyResult = ossClient.initiateMultipartUpload(initiateMultipartCopyRequest);
        Assert.assertEquals(initiateMultipartCopyResult.getRequestId().length(), requestIdLength);
        // upload part copy
        UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(bucketName, key, bucketName, key, initiateMultipartCopyResult.getUploadId(), 1, 0L, inputStreamLength);
        UploadPartCopyResult uploadPartCopyResult = ossClient.uploadPartCopy(uploadPartCopyRequest);
        Assert.assertEquals(uploadPartCopyResult.getRequestId().length(), requestIdLength);
        // abort multipart upload
        AbortMultipartUploadRequest AbortMultipartUploadRequest = new AbortMultipartUploadRequest(bucketName, key, initiateMultipartCopyResult.getUploadId());
        ossClient.abortMultipartUpload(AbortMultipartUploadRequest);
        ossClient.deleteObject(bucketName, key);
        file.delete();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : SimplifiedObjectMeta(com.aliyun.oss.model.SimplifiedObjectMeta) InitiateMultipartUploadResult(com.aliyun.oss.model.InitiateMultipartUploadResult) ArrayList(java.util.ArrayList) CompleteMultipartUploadResult(com.aliyun.oss.model.CompleteMultipartUploadResult) PartETag(com.aliyun.oss.model.PartETag) AppendObjectResult(com.aliyun.oss.model.AppendObjectResult) UploadPartResult(com.aliyun.oss.model.UploadPartResult) UploadPartCopyResult(com.aliyun.oss.model.UploadPartCopyResult) CopyObjectResult(com.aliyun.oss.model.CopyObjectResult) UploadPartCopyRequest(com.aliyun.oss.model.UploadPartCopyRequest) GetObjectRequest(com.aliyun.oss.model.GetObjectRequest) OSSObject(com.aliyun.oss.model.OSSObject) PutObjectResult(com.aliyun.oss.model.PutObjectResult) InitiateMultipartUploadRequest(com.aliyun.oss.model.InitiateMultipartUploadRequest) UploadPartRequest(com.aliyun.oss.model.UploadPartRequest) AbortMultipartUploadRequest(com.aliyun.oss.model.AbortMultipartUploadRequest) DeleteObjectsResult(com.aliyun.oss.model.DeleteObjectsResult) FileInputStream(java.io.FileInputStream) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) AppendObjectRequest(com.aliyun.oss.model.AppendObjectRequest) File(java.io.File) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) CompleteMultipartUploadRequest(com.aliyun.oss.model.CompleteMultipartUploadRequest) Test(org.junit.Test)

Example 2 with SimplifiedObjectMeta

use of com.aliyun.oss.model.SimplifiedObjectMeta in project aliyun-oss-java-sdk by aliyun.

the class ProgressBarTest method testDownloadFileProgressBar.

@Test
public void testDownloadFileProgressBar() throws Throwable {
    final String key = "download-file-progress-bar";
    final int instreamLength = 4 * 1024 * 1024;
    final String localFile = genFixedLengthFile(instreamLength);
    try {
        UploadFileRequest uploadFileRequest = new UploadFileRequest(bucketName, key);
        uploadFileRequest.setUploadFile(localFile);
        uploadFileRequest.setPartSize(1 * 1024 * 1024);
        uploadFileRequest.setTaskNum(3);
        uploadFileRequest.setProgressListener(new PutObjectProgressListener());
        ossClient.uploadFile(uploadFileRequest);
        SimplifiedObjectMeta metadata = ossClient.getSimplifiedObjectMeta(bucketName, key);
        Assert.assertEquals(instreamLength, metadata.getSize());
        DownloadFileRequest downloadFileRequest = new DownloadFileRequest(bucketName, key);
        downloadFileRequest.setDownloadFile(localFile + "-df.tmp");
        downloadFileRequest.setPartSize(1 * 1024 * 1024);
        downloadFileRequest.setTaskNum(3);
        downloadFileRequest.setProgressListener(new GetObjectProgressListener());
        ossClient.downloadFile(downloadFileRequest);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
Also used : UploadFileRequest(com.aliyun.oss.model.UploadFileRequest) SimplifiedObjectMeta(com.aliyun.oss.model.SimplifiedObjectMeta) DownloadFileRequest(com.aliyun.oss.model.DownloadFileRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with SimplifiedObjectMeta

use of com.aliyun.oss.model.SimplifiedObjectMeta in project aliyun-oss-java-sdk by aliyun.

the class GetSimplifiedObjectMetaTest method testNormalGetSimplifiedObjectMeta.

@Test
public void testNormalGetSimplifiedObjectMeta() {
    final String key = "normal-get-simplified-object-meta";
    final long inputStreamLength = 1024;
    try {
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, genFixedLengthInputStream(inputStreamLength), null);
        PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest);
        Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN);
        GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
        OSSObject o = ossClient.getObject(getObjectRequest);
        Assert.assertEquals(bucketName, o.getBucketName());
        Assert.assertEquals(key, o.getKey());
        Assert.assertEquals(inputStreamLength, o.getObjectMetadata().getContentLength());
        Assert.assertEquals(o.getRequestId().length(), REQUEST_ID_LEN);
        o.getObjectContent().close();
        SimplifiedObjectMeta objectMeta = ossClient.getSimplifiedObjectMeta(bucketName, key);
        Assert.assertEquals(inputStreamLength, objectMeta.getSize());
        Assert.assertEquals(putObjectResult.getETag(), objectMeta.getETag());
        Assert.assertNotNull(objectMeta.getLastModified());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SimplifiedObjectMeta(com.aliyun.oss.model.SimplifiedObjectMeta) OSSObject(com.aliyun.oss.model.OSSObject) PutObjectResult(com.aliyun.oss.model.PutObjectResult) GetObjectRequest(com.aliyun.oss.model.GetObjectRequest) PutObjectRequest(com.aliyun.oss.model.PutObjectRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Aggregations

SimplifiedObjectMeta (com.aliyun.oss.model.SimplifiedObjectMeta)3 Test (org.junit.Test)3 GetObjectRequest (com.aliyun.oss.model.GetObjectRequest)2 OSSObject (com.aliyun.oss.model.OSSObject)2 PutObjectResult (com.aliyun.oss.model.PutObjectResult)2 OSSException (com.aliyun.oss.OSSException)1 AbortMultipartUploadRequest (com.aliyun.oss.model.AbortMultipartUploadRequest)1 AppendObjectRequest (com.aliyun.oss.model.AppendObjectRequest)1 AppendObjectResult (com.aliyun.oss.model.AppendObjectResult)1 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)1 CopyObjectResult (com.aliyun.oss.model.CopyObjectResult)1 DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)1 DeleteObjectsResult (com.aliyun.oss.model.DeleteObjectsResult)1 DownloadFileRequest (com.aliyun.oss.model.DownloadFileRequest)1 InitiateMultipartUploadRequest (com.aliyun.oss.model.InitiateMultipartUploadRequest)1 InitiateMultipartUploadResult (com.aliyun.oss.model.InitiateMultipartUploadResult)1 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)1 PartETag (com.aliyun.oss.model.PartETag)1 PutObjectRequest (com.aliyun.oss.model.PutObjectRequest)1