sonar代码规范问题修复;

This commit is contained in:
gaoqr
2024-09-14 10:47:03 +08:00
parent 73440a7f3a
commit 59296b19c8
30 changed files with 75 additions and 72 deletions
@@ -18,6 +18,7 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
@Override
protected void doInit() {
// nothing
}
@Override
@@ -1,8 +1,9 @@
package com.cf.imes.framework.file.core.client.ftp;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ftp.Ftp;
import cn.hutool.extra.ftp.FtpException;
import cn.hutool.extra.ftp.FtpMode;
@@ -27,10 +28,10 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
@Override
protected void doInit() {
// 把配置的 \ 替换成 /, 如果路径配置 \a\test, 替换成 /a/test, 替换方法已经处理 null 情况
config.setBasePath(StrUtil.replace(config.getBasePath(), StrUtil.BACKSLASH, StrUtil.SLASH));
config.setBasePath(CharSequenceUtil.replace(config.getBasePath(), StrPool.BACKSLASH, StrPool.SLASH));
// ftp的路径是 / 结尾
if (!config.getBasePath().endsWith(StrUtil.SLASH)) {
config.setBasePath(config.getBasePath() + StrUtil.SLASH);
if (!config.getBasePath().endsWith(StrPool.SLASH)) {
config.setBasePath(config.getBasePath() + StrPool.SLASH);
}
// 初始化 Ftp 对象
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
@@ -42,11 +43,11 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
// 执行写入
String filePath = getFilePath(path);
String fileName = FileUtil.getName(filePath);
String dir = StrUtil.removeSuffix(filePath, fileName);
String dir = CharSequenceUtil.removeSuffix(filePath, fileName);
ftp.reconnectIfTimeout();
boolean success = ftp.upload(dir, fileName, new ByteArrayInputStream(content));
if (!success) {
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
throw new FtpException(CharSequenceUtil.format("上传文件到目标目录 ({}) 失败", filePath));
}
// 拼接返回路径
return super.formatFileUrl(config.getDomain(), path);
@@ -63,7 +64,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
public byte[] getContent(String path) {
String filePath = getFilePath(path);
String fileName = FileUtil.getName(filePath);
String dir = StrUtil.removeSuffix(filePath, fileName);
String dir = CharSequenceUtil.removeSuffix(filePath, fileName);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ftp.reconnectIfTimeout();
ftp.download(dir, fileName, out);