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());
}
}
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());
}
}
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());
}
}
Aggregations