mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
修复多线程下Sftp中Channel关闭的问题
This commit is contained in:
parent
7eb49299ea
commit
09f4abf75a
@ -638,6 +638,20 @@ public class NumberUtil extends NumberValidator {
|
||||
format.setMaximumFractionDigits(scale);
|
||||
return format.format(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化千分位表示方式,小数采用四舍五入方式
|
||||
*
|
||||
* @param number 值
|
||||
* @param scale 保留小数位数
|
||||
* @return 千分位数字
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static String formatThousands(final double number, final int scale) {
|
||||
final NumberFormat format = NumberFormat.getNumberInstance();
|
||||
format.setMaximumFractionDigits(scale);
|
||||
return format.format(number);
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region ----- range
|
||||
|
@ -746,4 +746,12 @@ public class NumberUtilTest {
|
||||
void issueI6ZD1RTest() {
|
||||
Assertions.assertFalse(NumberUtil.isInteger("999999999999999"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void formatThousands() {
|
||||
// issue#I7OIA6
|
||||
Assertions.assertEquals(
|
||||
"123,456,789.111111",
|
||||
NumberUtil.formatThousands(123456789.111111D, 6));
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +245,9 @@ public class Sftp extends AbstractFtp {
|
||||
* @since 4.1.14
|
||||
*/
|
||||
public ChannelSftp getClient() {
|
||||
if(false == this.channel.isConnected()){
|
||||
init();
|
||||
}
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
@ -256,7 +259,7 @@ public class Sftp extends AbstractFtp {
|
||||
@Override
|
||||
public String pwd() {
|
||||
try {
|
||||
return channel.pwd();
|
||||
return getClient().pwd();
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -270,7 +273,7 @@ public class Sftp extends AbstractFtp {
|
||||
*/
|
||||
public String home() {
|
||||
try {
|
||||
return channel.getHome();
|
||||
return getClient().getHome();
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -351,7 +354,7 @@ public class Sftp extends AbstractFtp {
|
||||
public List<LsEntry> lsEntries(final String path, final Predicate<LsEntry> predicate) {
|
||||
final List<LsEntry> entryList = new ArrayList<>();
|
||||
try {
|
||||
channel.ls(path, entry -> {
|
||||
getClient().ls(path, entry -> {
|
||||
final String fileName = entry.getFilename();
|
||||
if (!StrUtil.equals(".", fileName) && !StrUtil.equals("..", fileName)) {
|
||||
if (null == predicate || predicate.test(entry)) {
|
||||
@ -376,7 +379,7 @@ public class Sftp extends AbstractFtp {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
this.channel.mkdir(dir);
|
||||
getClient().mkdir(dir);
|
||||
return true;
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
@ -387,7 +390,7 @@ public class Sftp extends AbstractFtp {
|
||||
public boolean isDir(final String dir) {
|
||||
final SftpATTRS sftpATTRS;
|
||||
try {
|
||||
sftpATTRS = this.channel.stat(dir);
|
||||
sftpATTRS = getClient().stat(dir);
|
||||
} catch (final SftpException e) {
|
||||
final String msg = e.getMessage();
|
||||
// issue#I4P9ED@Gitee
|
||||
@ -415,7 +418,7 @@ public class Sftp extends AbstractFtp {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
channel.cd(directory.replace('\\', '/'));
|
||||
getClient().cd(directory.replace('\\', '/'));
|
||||
return true;
|
||||
} catch (final SftpException e) {
|
||||
throw new FtpException(e);
|
||||
@ -430,7 +433,7 @@ public class Sftp extends AbstractFtp {
|
||||
@Override
|
||||
public boolean delFile(final String filePath) {
|
||||
try {
|
||||
channel.rm(filePath);
|
||||
getClient().rm(filePath);
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -450,6 +453,8 @@ public class Sftp extends AbstractFtp {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ChannelSftp channel = getClient();
|
||||
|
||||
final Vector<LsEntry> list;
|
||||
try {
|
||||
list = channel.ls(channel.pwd());
|
||||
@ -576,7 +581,7 @@ public class Sftp extends AbstractFtp {
|
||||
*/
|
||||
public Sftp put(final String srcFilePath, final String destPath, final SftpProgressMonitor monitor, final Mode mode) {
|
||||
try {
|
||||
channel.put(srcFilePath, destPath, monitor, mode.ordinal());
|
||||
getClient().put(srcFilePath, destPath, monitor, mode.ordinal());
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -595,7 +600,7 @@ public class Sftp extends AbstractFtp {
|
||||
*/
|
||||
public Sftp put(final InputStream srcStream, final String destPath, final SftpProgressMonitor monitor, final Mode mode) {
|
||||
try {
|
||||
channel.put(srcStream, destPath, monitor, mode.ordinal());
|
||||
getClient().put(srcStream, destPath, monitor, mode.ordinal());
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -658,7 +663,7 @@ public class Sftp extends AbstractFtp {
|
||||
*/
|
||||
public Sftp get(final String src, final String dest) {
|
||||
try {
|
||||
channel.get(src, dest);
|
||||
getClient().get(src, dest);
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
@ -675,7 +680,7 @@ public class Sftp extends AbstractFtp {
|
||||
*/
|
||||
public Sftp get(final String src, final OutputStream out) {
|
||||
try {
|
||||
channel.get(src, out);
|
||||
getClient().get(src, out);
|
||||
} catch (final SftpException e) {
|
||||
throw new JschRuntimeException(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user