Search in sources :

Example 1 with OssException

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);
}
Also used : OssException(io.github.artislong.exception.OssException) UfileClientException(cn.ucloud.ufile.exception.UfileClientException) OssException(io.github.artislong.exception.OssException)

Example 2 with OssException

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);
        }
    }
}
Also used : OssException(io.github.artislong.exception.OssException) UfileClientException(cn.ucloud.ufile.exception.UfileClientException) OssException(io.github.artislong.exception.OssException)

Example 3 with OssException

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);
    }
}
Also used : DownloadObjectStat(io.github.artislong.model.download.DownloadObjectStat) ObjectProfile(cn.ucloud.ufile.bean.ObjectProfile) DateTime(cn.hutool.core.date.DateTime) OssException(io.github.artislong.exception.OssException) UfileClientException(cn.ucloud.ufile.exception.UfileClientException) OssException(io.github.artislong.exception.OssException)

Example 4 with OssException

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;
}
Also used : ObjectInfoBean(cn.ucloud.ufile.bean.ObjectInfoBean) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) FileOssInfo(io.github.artislong.model.FileOssInfo) OssInfo(io.github.artislong.model.OssInfo) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) OssException(io.github.artislong.exception.OssException) UfileClientException(cn.ucloud.ufile.exception.UfileClientException) OssException(io.github.artislong.exception.OssException) ObjectListBean(cn.ucloud.ufile.bean.ObjectListBean) FileOssInfo(io.github.artislong.model.FileOssInfo)

Example 5 with OssException

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);
    }
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) RestManager(com.upyun.RestManager) ObjectUtil(cn.hutool.core.util.ObjectUtil) StandardOssClient(io.github.artislong.core.StandardOssClient) HashMap(java.util.HashMap) Headers(okhttp3.Headers) ArrayList(java.util.ArrayList) FileOssInfo(io.github.artislong.model.FileOssInfo) OssInfo(io.github.artislong.model.OssInfo) OssException(io.github.artislong.exception.OssException) Map(java.util.Map) Response(okhttp3.Response) ParallelUploader(com.upyun.ParallelUploader) IoUtil(cn.hutool.core.io.IoUtil) LineHandler(cn.hutool.core.io.LineHandler) OssPathUtil(io.github.artislong.utils.OssPathUtil) FileNameUtil(cn.hutool.core.io.file.FileNameUtil) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) UpOssConfig(io.github.artislong.core.up.model.UpOssConfig) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) java.io(java.io) UpException(com.upyun.UpException) ReflectUtil(cn.hutool.core.util.ReflectUtil) Data(lombok.Data) Convert(cn.hutool.core.convert.Convert) UpConstant(io.github.artislong.core.up.constant.UpConstant) AllArgsConstructor(lombok.AllArgsConstructor) DatePattern(cn.hutool.core.date.DatePattern) NoArgsConstructor(lombok.NoArgsConstructor) UpException(com.upyun.UpException) ArrayList(java.util.ArrayList) OssException(io.github.artislong.exception.OssException) Response(okhttp3.Response) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) ArrayList(java.util.ArrayList) List(java.util.List) FileOssInfo(io.github.artislong.model.FileOssInfo) OssInfo(io.github.artislong.model.OssInfo) DirectoryOssInfo(io.github.artislong.model.DirectoryOssInfo) FileOssInfo(io.github.artislong.model.FileOssInfo)

Aggregations

OssException (io.github.artislong.exception.OssException)44 QSException (com.qingstor.sdk.exception.QSException)9 Bucket (com.qingstor.sdk.service.Bucket)9 DirectoryOssInfo (io.github.artislong.model.DirectoryOssInfo)9 FileOssInfo (io.github.artislong.model.FileOssInfo)9 OssInfo (io.github.artislong.model.OssInfo)9 UfileClientException (cn.ucloud.ufile.exception.UfileClientException)7 QiniuException (com.qiniu.common.QiniuException)4 DownloadCheckPoint (io.github.artislong.model.download.DownloadCheckPoint)4 DownloadObjectStat (io.github.artislong.model.download.DownloadObjectStat)4 ArrayList (java.util.ArrayList)4 ObjectProfile (cn.ucloud.ufile.bean.ObjectProfile)3 UpException (com.upyun.UpException)3 AmazonClientException (repkg.com.amazonaws.AmazonClientException)3 DateTime (cn.hutool.core.date.DateTime)2 Ftp (cn.hutool.extra.ftp.Ftp)2 DownloadFileBean (cn.ucloud.ufile.bean.DownloadFileBean)2 DownloadUrl (com.qiniu.storage.DownloadUrl)2 SliceConfig (io.github.artislong.model.SliceConfig)2 UpLoadCheckPoint (io.github.artislong.model.upload.UpLoadCheckPoint)2