use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.
the class COSObjectStorageServiceImpl method getObjectMetadata.
/**
* {@inheritDoc}
*/
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws CloudSDKException {
try {
ObjectMetadata objectMetadata = null;
com.qcloud.cos.model.ObjectMetadata metadata = cosClient.getObjectMetadata(bucketName, objectName);
if (null != metadata) {
objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(metadata.getContentLength());
objectMetadata.setContentMD5(metadata.getContentMD5());
objectMetadata.setContentType(metadata.getContentType());
objectMetadata.setLastModified(metadata.getLastModified());
objectMetadata.setObjectName(objectName);
return objectMetadata;
} else {
throw new CloudSDKException("ObjectName not found.");
}
} catch (Throwable e) {
throw new CloudSDKException(e.getMessage(), e);
}
}
use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.
the class COSObjectStorageServiceImpl method copyObject.
/**
* {@inheritDoc}
*/
@Override
public void copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws CloudSDKException {
try {
CopyObjectRequest request = new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey);
cosClient.copyObject(request);
} catch (Throwable e) {
throw new CloudSDKException(e.getMessage(), e);
}
}
use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.
the class AliyunObjectStorageServiceImpl method genPresignedUploadUrl.
/**
* {@inheritDoc}
*/
@Override
public URL genPresignedUploadUrl(String bucketName, String objectName, long signExpired, String contentMd5) throws CloudSDKException {
try {
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.PUT);
req.setContentMD5(contentMd5);
Date expirationDate = new Date(System.currentTimeMillis() + signExpired);
req.setExpiration(expirationDate);
URL downloadUrl = ossClient.generatePresignedUrl(req);
return downloadUrl;
} catch (Throwable e) {
throw new CloudSDKException(e.getMessage(), e);
}
}
use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.
the class AliyunObjectStorageServiceImpl method putObject.
/**
* {@inheritDoc}
*/
@Override
public void putObject(String bucketName, String objectName, InputStream input, long contentLength, String contentType) throws CloudSDKException {
try {
com.aliyun.oss.model.ObjectMetadata metadata = new com.aliyun.oss.model.ObjectMetadata();
metadata.setContentLength(contentLength);
metadata.setContentType(contentType);
ossClient.putObject(bucketName, objectName, input, metadata);
} catch (Throwable e) {
throw new CloudSDKException(e.getMessage(), e);
} finally {
try {
input.close();
} catch (Throwable e) {
LOG.error("Close file input stream failed.", e);
}
}
}
use of com.mizhousoft.cloudsdk.CloudSDKException in project cloud-sdk by mizhousoft.
the class AliyunObjectStorageServiceImpl method getObjectMetadata.
/**
* {@inheritDoc}
*/
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws CloudSDKException {
try {
ObjectMetadata objectMetadata = null;
com.aliyun.oss.model.ObjectMetadata metadata = ossClient.getObjectMetadata(bucketName, objectName);
if (null != metadata) {
objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(metadata.getContentLength());
objectMetadata.setContentMD5(metadata.getContentMD5());
objectMetadata.setContentType(metadata.getContentType());
objectMetadata.setLastModified(metadata.getLastModified());
objectMetadata.setObjectName(objectName);
return objectMetadata;
} else {
throw new CloudSDKException("ObjectName not found.");
}
} catch (Throwable e) {
throw new CloudSDKException(e.getMessage(), e);
}
}
Aggregations