use of io.github.artislong.model.DirectoryOssInfo 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.model.DirectoryOssInfo 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 io.github.artislong.model.DirectoryOssInfo 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 io.github.artislong.model.DirectoryOssInfo in project oss-spring-boot-starter by ArtIsLong.
the class JinShanOssClient 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);
ObjectListing listObjects = ks3.listObjects(getBucket(), prefix.endsWith("/") ? prefix : prefix + CharPool.SLASH);
List<OssInfo> fileOssInfos = new ArrayList<>();
List<OssInfo> directoryInfos = new ArrayList<>();
if (ObjectUtil.isNotEmpty(listObjects.getObjectSummaries())) {
for (Ks3ObjectSummary ks3ObjectSummary : listObjects.getObjectSummaries()) {
if (FileNameUtil.getName(ks3ObjectSummary.getKey()).equals(FileNameUtil.getName(key))) {
ossInfo.setLastUpdateTime(DateUtil.date(ks3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setCreateTime(DateUtil.date(ks3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setLength(Convert.toStr(ks3ObjectSummary.getSize()));
} else {
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(ks3ObjectSummary.getKey(), getBasePath(), false), false));
}
}
}
if (ObjectUtil.isNotEmpty(listObjects.getCommonPrefixes())) {
for (String commonPrefix : listObjects.getCommonPrefixes()) {
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
if (isDirectory(commonPrefix)) {
directoryInfos.add(getInfo(target, true));
} else {
fileOssInfos.add(getInfo(target, 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.model.DirectoryOssInfo in project oss-spring-boot-starter by ArtIsLong.
the class JinShanOssClient method getBaseInfo.
public OssInfo getBaseInfo(String key) {
OssInfo ossInfo;
if (isFile(key)) {
ossInfo = new FileOssInfo();
try {
GetObjectResult objectResult = ks3.getObject(getBucket(), key);
ObjectMetadata objectMetadata = objectResult.getObject().getObjectMetadata();
ossInfo.setLastUpdateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setCreateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
ossInfo.setLength(Convert.toStr(objectMetadata.getContentLength()));
} catch (Exception e) {
log.error("获取{}文件属性失败", key, e);
}
} else {
ossInfo = new DirectoryOssInfo();
}
return ossInfo;
}
Aggregations