mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
修复Sftp.upload目标路径为null时空指针问题(issue#ID14WX@Gitee)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.41(2025-09-29)
|
||||
# 5.8.41(2025-10-10)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加`WeakKeyValueConcurrentMap`及其关联类,同时废弃`WeakConcurrentMap`并替换(issue#4039@Github)
|
||||
@@ -33,6 +33,7 @@
|
||||
* 【extra 】 修复`JschSessionPool`并发问题(pr#4079@Github)
|
||||
* 【extra 】 修复`Sftp`递归删除目录时使用相对路径可能导致死循环的问题(pr#1380@Gitee)
|
||||
* 【db 】 修复`SqlUtil.removeOuterOrderBy`处理没有order by的语句导致异常问题(pr#4089@Github)
|
||||
* 【extra 】 修复`Sftp.upload`目标路径为null时空指针问题(issue#ID14WX@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.40(2025-08-26)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -633,14 +634,14 @@ public class StrUtilTest {
|
||||
public void replaceLastTest() {
|
||||
final String str = "i am jackjack";
|
||||
final String result = StrUtil.replaceLast(str, "JACK", null, true);
|
||||
assertEquals(result, "i am jack");
|
||||
assertEquals("i am jack", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceFirstTest() {
|
||||
final String str = "yesyes i do";
|
||||
final String result = StrUtil.replaceFirst(str, "YES", "", true);
|
||||
assertEquals(result, "yes i do");
|
||||
assertEquals("yes i do", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.hutool.extra.ssh;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ftp.AbstractFtp;
|
||||
@@ -538,7 +539,8 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public boolean upload(String destPath, String fileName, InputStream fileStream) {
|
||||
destPath = StrUtil.addSuffixIfNot(destPath, StrUtil.SLASH) + StrUtil.removePrefix(fileName, StrUtil.SLASH);
|
||||
Assert.notEmpty(fileName);
|
||||
destPath = StrUtil.addSuffixIfNot(StrUtil.nullToEmpty(destPath), StrUtil.SLASH) + StrUtil.removePrefix(fileName, StrUtil.SLASH);
|
||||
put(fileStream, destPath, null, Mode.OVERWRITE);
|
||||
return true;
|
||||
}
|
||||
@@ -570,13 +572,16 @@ public class Sftp extends AbstractFtp {
|
||||
* 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。
|
||||
*
|
||||
* @param srcFilePath 本地文件路径
|
||||
* @param destPath 目标路径,
|
||||
* @param destPath 目标路径,{@code null}表示当前路径
|
||||
* @param monitor 上传进度监控,通过实现此接口完成进度显示
|
||||
* @param mode {@link Mode} 模式
|
||||
* @return this
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public Sftp put(String srcFilePath, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||
public Sftp put(String srcFilePath, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||
if(null == destPath){
|
||||
destPath = pwd();
|
||||
}
|
||||
try {
|
||||
getClient().put(srcFilePath, destPath, monitor, mode.ordinal());
|
||||
} catch (SftpException e) {
|
||||
@@ -589,13 +594,16 @@ public class Sftp extends AbstractFtp {
|
||||
* 将本地数据流上传到目标服务器,目标文件名为destPath,目标必须为文件
|
||||
*
|
||||
* @param srcStream 本地的数据流
|
||||
* @param destPath 目标路径,
|
||||
* @param destPath 目标路径,{@code null}表示当前路径
|
||||
* @param monitor 上传进度监控,通过实现此接口完成进度显示
|
||||
* @param mode {@link Mode} 模式
|
||||
* @return this
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public Sftp put(InputStream srcStream, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||
if(null == destPath){
|
||||
destPath = pwd();
|
||||
}
|
||||
try {
|
||||
getClient().put(srcStream, destPath, monitor, mode.ordinal());
|
||||
} catch (SftpException e) {
|
||||
|
||||
Reference in New Issue
Block a user