use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method exists.
@Override
public boolean exists(String bucketName, String fileKey) {
bucketName = buildBucketName(bucketName);
fileKey = resolveFileKey(bucketName, fileKey);
try {
bucketManager.stat(bucketName, fileKey);
return true;
} catch (QiniuException e) {
if (e.code() == 612)
return false;
throw new JeesuiteBaseException(e.code(), e.getMessage());
}
}
use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class AliyunProvider method getObjectMetadata.
@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
try {
bucketName = buildBucketName(bucketName);
fileKey = resolveFileKey(bucketName, fileKey);
ObjectMetadata metadata = ossClient.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, e.getMessage());
}
}
use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QcloudProvider method delete.
@Override
public boolean delete(String bucketName, String fileKey) {
try {
bucketName = buildBucketName(bucketName);
cosclient.deleteObject(bucketName, fileKey);
} catch (Exception e) {
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
return true;
}
use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QcloudProvider method upload.
@Override
public CUploadResult upload(CUploadObject object) {
PutObjectRequest request;
String fileKey = object.getFileKey();
String bucketName = buildBucketName(object.getBucketName());
if (object.getFile() != null) {
request = new PutObjectRequest(bucketName, fileKey, object.getFile());
} else if (object.getBytes() != null) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
} else if (object.getInputStream() != null) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(object.getFileSize());
request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
} else {
throw new IllegalArgumentException("upload object is NULL");
}
try {
if (object.getFileSize() > conf.getMaxAllowdSingleFileSize()) {
Upload upload = transferManager.upload(request);
com.qcloud.cos.model.UploadResult result = upload.waitForUploadResult();
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getCrc64Ecma());
} else {
PutObjectResult result = cosclient.putObject(request);
return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getContentMd5());
}
} catch (Exception e) {
e.printStackTrace();
throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
}
}
use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class TokenGenerator method validate.
/**
* 验证带签名信息的token
*/
public static void validate(String tokenType, String token, boolean validateExpire) {
long timestamp = 0;
Date date = new Date();
try {
if (tokenType == null) {
timestamp = Long.parseLong(SimpleCryptUtils.decrypt(token).substring(6));
} else {
String cryptKey = getCryptKey(tokenType);
timestamp = Long.parseLong(DES.decrypt(cryptKey, token).substring(6));
}
} catch (Exception e) {
throw new JeesuiteBaseException(4005, "token格式错误");
}
if (validateExpire && date.getTime() - timestamp > EXPIRE) {
throw new JeesuiteBaseException(4005, "token已过期");
}
}
Aggregations