use of com.upyun.UpException in project oss-spring-boot-starter by ArtIsLong.
the class UpOssClient method getDirectoryOssInfo.
private DirectoryOssInfo getDirectoryOssInfo(String key) throws UpException, IOException {
String name = FileNameUtil.getName(key);
String newKey = OssPathUtil.replaceKey(key, name, true);
Response response = restManager.readDirIter(newKey, null);
DirectoryOssInfo ossInfo = new DirectoryOssInfo();
IoUtil.readUtf8Lines(response.body().byteStream(), (LineHandler) line -> {
List<String> fields = StrUtil.split(line, "\t");
if (name.equals(fields.get(0))) {
ossInfo.setName(fields.get(0));
ossInfo.setPath(OssPathUtil.replaceKey(newKey, getBasePath(), true));
ossInfo.setLength(fields.get(2));
ossInfo.setCreateTime(DateUtil.date(Convert.toLong(fields.get(3)) * 1000).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setLastUpdateTime(DateUtil.date(Convert.toLong(fields.get(3)) * 1000).toString(DatePattern.NORM_DATETIME_PATTERN));
}
});
return ossInfo;
}
use of com.upyun.UpException in project oss-spring-boot-starter by ArtIsLong.
the class UpOssClient method getInfo.
@Override
public OssInfo getInfo(String targetName, Boolean isRecursion) {
String key = getKey(targetName, true);
try {
OssInfo ossInfo = getBaseInfo(key);
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
if (isRecursion && isDirectory(key)) {
List<OssInfo> fileOssInfos = new ArrayList<>();
List<OssInfo> directoryInfos = new ArrayList<>();
Response response = restManager.readDirIter(key, null);
IoUtil.readUtf8Lines(response.body().byteStream(), (LineHandler) line -> {
List<String> fields = StrUtil.split(line, "\t");
if (UpConstant.FILE_TYPE.equals(fields.get(1))) {
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(key + StrUtil.SLASH + fields.get(0), getBasePath(), true), true));
} else {
directoryInfos.add(getInfo(OssPathUtil.replaceKey(key + StrUtil.SLASH + fields.get(0), getBasePath(), true), true));
}
});
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
}
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
}
}
return ossInfo;
} catch (IOException | UpException e) {
log.error("获取{}基本信息失败", targetName, e);
throw new OssException(e);
}
}
use of com.upyun.UpException in project oss-spring-boot-starter by ArtIsLong.
the class UpOssClient method downLoad.
@Override
public void downLoad(OutputStream os, String targetName) {
try {
Response response = restManager.readFile(getKey(targetName, true));
IoUtil.copy(response.body().byteStream(), os);
} catch (IOException | UpException e) {
log.error("{}下载失败", targetName, e);
throw new OssException(e);
}
}
use of com.upyun.UpException in project halo by halo-dev.
the class UpOssFileHandler method delete.
@Override
public void delete(String key) {
Assert.notNull(key, "File key must not be blank");
// Get config
String password = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_PASSWORD).toString();
String bucket = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_BUCKET).toString();
String operator = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_OPERATOR).toString();
RestManager manager = new RestManager(bucket, operator, password);
manager.setTimeout(60 * 10);
manager.setApiDomain(RestManager.ED_AUTO);
try {
Response result = manager.deleteFile(key, null);
if (!result.isSuccessful()) {
log.warn("附件 " + key + " 从又拍云删除失败");
throw new FileOperationException("附件 " + key + " 从又拍云删除失败");
}
} catch (IOException | UpException e) {
e.printStackTrace();
throw new FileOperationException("附件 " + key + " 从又拍云删除失败", e);
}
}
use of com.upyun.UpException in project halo-plugin-experimental by guqing.
the class UpOssFileHandler method delete.
@Override
public void delete(String key) {
Assert.notNull(key, "File key must not be blank");
// Get config
String password = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_PASSWORD).toString();
String bucket = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_BUCKET).toString();
String operator = optionService.getByPropertyOfNonNull(UpOssProperties.OSS_OPERATOR).toString();
RestManager manager = new RestManager(bucket, operator, password);
manager.setTimeout(60 * 10);
manager.setApiDomain(RestManager.ED_AUTO);
try {
Response result = manager.deleteFile(key, null);
if (!result.isSuccessful()) {
log.warn("附件 " + key + " 从又拍云删除失败");
throw new FileOperationException("附件 " + key + " 从又拍云删除失败");
}
} catch (IOException | UpException e) {
e.printStackTrace();
throw new FileOperationException("附件 " + key + " 从又拍云删除失败", e);
}
}
Aggregations