mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
a77dce46cd
commit
32684b2d5c
@ -12,10 +12,12 @@
|
||||
* 【core 】 MailAccount中charset增加null时的默认规则
|
||||
* 【core 】 NumberUtil.compare修正注释说明(issue#I4FAJ1@Gitee)
|
||||
* 【core 】 增加RFC3986类
|
||||
* 【extra 】 Sftp增加put和upload重载(issue#I4FGDH@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
||||
* 【core 】 修复StrBuilder中总长度计算问题(issue#I4F9L7@Gitee)
|
||||
* 【core 】 修复CharSequenceUtil.wrapIfMissing预定义长度计算问题(issue#I4FDZ2@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -2857,10 +2857,10 @@ public class CharSequenceUtil {
|
||||
len += str.length();
|
||||
}
|
||||
if (isNotEmpty(prefix)) {
|
||||
len += str.length();
|
||||
len += prefix.length();
|
||||
}
|
||||
if (isNotEmpty(suffix)) {
|
||||
len += str.length();
|
||||
len += suffix.length();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
if (isNotEmpty(prefix) && false == startWith(str, prefix)) {
|
||||
|
@ -489,9 +489,9 @@ public class Ftp extends AbstractFtp {
|
||||
* 上传文件到指定目录,可选:
|
||||
*
|
||||
* <pre>
|
||||
* 1. path为null或""上传到当前路径
|
||||
* 2. path为相对路径则相对于当前路径的子路径
|
||||
* 3. path为绝对路径则上传到此路径
|
||||
* 1. destPath为null或""上传到当前路径
|
||||
* 2. destPath为相对路径则相对于当前路径的子路径
|
||||
* 3. destPath为绝对路径则上传到此路径
|
||||
* </pre>
|
||||
*
|
||||
* @param file 文件
|
||||
@ -512,9 +512,9 @@ public class Ftp extends AbstractFtp {
|
||||
* 上传文件到指定目录,可选:
|
||||
*
|
||||
* <pre>
|
||||
* 1. path为null或""上传到当前路径
|
||||
* 2. path为相对路径则相对于当前路径的子路径
|
||||
* 3. path为绝对路径则上传到此路径
|
||||
* 1. destPath为null或""上传到当前路径
|
||||
* 2. destPath为相对路径则相对于当前路径的子路径
|
||||
* 3. destPath为绝对路径则上传到此路径
|
||||
* </pre>
|
||||
*
|
||||
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
|
||||
|
@ -17,6 +17,7 @@ import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.SftpProgressMonitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@ -337,7 +338,7 @@ public class Sftp extends AbstractFtp {
|
||||
try {
|
||||
sftpATTRS = this.channel.stat(dir);
|
||||
} catch (SftpException e) {
|
||||
if(e.getMessage().contains("No such file")){
|
||||
if (e.getMessage().contains("No such file")) {
|
||||
// 文件不存在直接返回false
|
||||
// pr#378@Gitee
|
||||
return false;
|
||||
@ -464,6 +465,27 @@ public class Sftp extends AbstractFtp {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到指定目录,可选:
|
||||
*
|
||||
* <pre>
|
||||
* 1. path为null或""上传到当前路径
|
||||
* 2. path为相对路径则相对于当前路径的子路径
|
||||
* 3. path为绝对路径则上传到此路径
|
||||
* </pre>
|
||||
*
|
||||
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
|
||||
* @param fileName 文件名
|
||||
* @param fileStream 文件流
|
||||
* @return 是否上传成功
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public boolean upload(String destPath, String fileName, InputStream fileStream) {
|
||||
destPath = StrUtil.addSuffixIfNot(destPath, StrUtil.SLASH) + StrUtil.removePrefix(fileName, StrUtil.SLASH);
|
||||
put(fileStream, destPath, null, Mode.OVERWRITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。覆盖模式
|
||||
*
|
||||
@ -506,6 +528,25 @@ public class Sftp extends AbstractFtp {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地数据流上传到目标服务器,目标文件名为destPath,目标必须为文件
|
||||
*
|
||||
* @param srcStream 本地的数据流
|
||||
* @param destPath 目标路径,
|
||||
* @param monitor 上传进度监控,通过实现此接口完成进度显示
|
||||
* @param mode {@link Mode} 模式
|
||||
* @return this
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public Sftp put(InputStream srcStream, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||
try {
|
||||
channel.put(srcStream, destPath, monitor, mode.ordinal());
|
||||
} catch (SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String src, File destFile) {
|
||||
get(src, FileUtil.getAbsolutePath(destFile));
|
||||
|
Loading…
x
Reference in New Issue
Block a user