use of io.github.artislong.exception.OssException in project oss-spring-boot-starter by ArtIsLong.
the class UCloudOssClient method upLoad.
@Override
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
String bucketName = getBucket();
String key = getKey(targetName, false);
if (isOverride || !isExist(targetName)) {
try {
objectApiBuilder.putObject(is, 0, "").nameAs(key).toBucket(bucketName).execute();
} catch (Exception e) {
throw new OssException(e);
}
}
return getInfo(targetName);
}
use of io.github.artislong.exception.OssException in project oss-spring-boot-starter by ArtIsLong.
the class UCloudOssClient method copy.
@Override
public void copy(String sourceName, String targetName, Boolean isOverride) {
String bucketName = getBucket();
String targetKey = getKey(targetName, false);
if (isOverride || !isExist(targetName)) {
try {
objectApiBuilder.copyObject(bucketName, getKey(sourceName, false)).copyTo(bucketName, targetKey).execute();
} catch (Exception e) {
throw new OssException(e);
}
}
}
use of io.github.artislong.exception.OssException in project oss-spring-boot-starter by ArtIsLong.
the class UCloudOssClient method getDownloadObjectStat.
@Override
public DownloadObjectStat getDownloadObjectStat(String targetName) {
try {
ObjectProfile objectProfile = objectApiBuilder.objectProfile(getKey(targetName, false), getBucket()).execute();
DateTime date = DateUtil.parse(objectProfile.getLastModified());
long contentLength = objectProfile.getContentLength();
String eTag = objectProfile.geteTag();
return new DownloadObjectStat().setSize(contentLength).setLastModified(date).setDigest(eTag);
} catch (Exception e) {
throw new OssException(e);
}
}
use of io.github.artislong.exception.OssException in project oss-spring-boot-starter by ArtIsLong.
the class UCloudOssClient method getInfo.
@Override
public OssInfo getInfo(String targetName, Boolean isRecursion) {
String key = getKey(targetName, false);
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)) {
String prefix = OssPathUtil.convertPath(key, false);
ObjectListBean objectListBean;
try {
objectListBean = objectApiBuilder.objectList(getBucket()).withPrefix(prefix.endsWith("/") ? prefix : prefix + CharPool.SLASH).execute();
} catch (Exception e) {
throw new OssException(e);
}
List<ObjectInfoBean> objectList = objectListBean.getObjectList();
List<OssInfo> fileOssInfos = new ArrayList<>();
List<OssInfo> directoryInfos = new ArrayList<>();
for (ObjectInfoBean objectInfoBean : objectList) {
String fileName = objectInfoBean.getFileName();
if (FileNameUtil.getName(fileName).equals(FileNameUtil.getName(key))) {
ossInfo.setLastUpdateTime(DateUtil.date(objectInfoBean.getModifyTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setCreateTime(DateUtil.date(objectInfoBean.getCreateTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setLength(Convert.toStr(objectInfoBean.getSize()));
} else if (isDirectory(fileName)) {
directoryInfos.add(getInfo(OssPathUtil.replaceKey(fileName, getBasePath(), false), true));
} else {
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(fileName, getBasePath(), false), false));
}
}
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;
}
use of io.github.artislong.exception.OssException 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);
}
}
Aggregations