mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
sonar代码规范问题修复;
This commit is contained in:
+1
@@ -18,6 +18,7 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-7
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user