Search in sources :

Example 6 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method getObjectInputStream.

@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
    bucketName = buildBucketName(bucketName);
    String downloadUrl = getDownloadUrl(bucketName, fileKey, 600);
    Request request = new Request.Builder().url(downloadUrl).build();
    okhttp3.Response re = null;
    try {
        re = httpClient.newCall(request).execute();
        if (re.isSuccessful()) {
            return re.body().byteStream();
        }
        throw new JeesuiteBaseException(re.code(), re.message());
    } catch (IOException e) {
        throw new JeesuiteBaseException(e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) Request(okhttp3.Request) IOException(java.io.IOException)

Example 7 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class AliyunProvider method createBucket.

@Override
public void createBucket(String bucketName, boolean isPrivate) {
    if (ossClient.doesBucketExist(bucketName)) {
        throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
    }
    CreateBucketRequest request = new CreateBucketRequest(bucketName);
    if (isPrivate) {
        request.setCannedACL(CannedAccessControlList.Private);
    } else {
        request.setCannedACL(CannedAccessControlList.PublicRead);
    }
    ossClient.createBucket(request);
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) CreateBucketRequest(com.aliyun.oss.model.CreateBucketRequest)

Example 8 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method getObjectInputStream.

@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
    try {
        String _bucketName = buildBucketName(bucketName);
        String _fileKey = resolveFileKey(bucketName, fileKey);
        COSObject cosObject = cosclient.getObject(_bucketName, _fileKey);
        return cosObject.getObjectContent();
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) COSObject(com.qcloud.cos.model.COSObject) CosServiceException(com.qcloud.cos.exception.CosServiceException) IOException(java.io.IOException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 9 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method createBucket.

@Override
public void createBucket(String bucketName, boolean isPrivate) {
    bucketName = buildBucketName(bucketName);
    if (cosclient.doesBucketExist(bucketName)) {
        throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
    }
    CreateBucketRequest request = new CreateBucketRequest(bucketName);
    if (isPrivate) {
        request.setCannedAcl(CannedAccessControlList.Private);
    } else {
        request.setCannedAcl(CannedAccessControlList.PublicRead);
    }
    cosclient.createBucket(request);
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest)

Example 10 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        String _bucketName = buildBucketName(bucketName);
        String _fileKey = resolveFileKey(bucketName, fileKey);
        ObjectMetadata metadata = cosclient.getObjectMetadata(_bucketName, _fileKey);
        CObjectMetadata objectMetadata = new CObjectMetadata();
        objectMetadata.setCreateTime(metadata.getLastModified());
        objectMetadata.setMimeType(metadata.getContentType());
        objectMetadata.setFilesize(metadata.getContentLength());
        objectMetadata.setHash(metadata.getContentMD5());
        objectMetadata.setExpirationTime(metadata.getExpirationTime());
        objectMetadata.setCustomMetadatas(metadata.getUserMetadata());
        return objectMetadata;
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
    }
}
Also used : CObjectMetadata(com.jeesuite.cos.CObjectMetadata) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) CObjectMetadata(com.jeesuite.cos.CObjectMetadata) CosServiceException(com.qcloud.cos.exception.CosServiceException) IOException(java.io.IOException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)41 IOException (java.io.IOException)14 Request (okhttp3.Request)7 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 CObjectMetadata (com.jeesuite.cos.CObjectMetadata)3 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SignatureException (java.security.SignatureException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CUploadResult (com.jeesuite.cos.CUploadResult)2 WrapperResponseEntity (com.jeesuite.springweb.model.WrapperResponseEntity)2 COSObject (com.qcloud.cos.model.COSObject)2 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)2 QiniuException (com.qiniu.common.QiniuException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2