mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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);
|
format.setMaximumFractionDigits(scale);
|
||||||
return format.format(number);
|
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
|
// endregion
|
||||||
|
|
||||||
// region ----- range
|
// region ----- range
|
||||||
|
@ -746,4 +746,12 @@ public class NumberUtilTest {
|
|||||||
void issueI6ZD1RTest() {
|
void issueI6ZD1RTest() {
|
||||||
Assertions.assertFalse(NumberUtil.isInteger("999999999999999"));
|
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
|
* @since 4.1.14
|
||||||
*/
|
*/
|
||||||
public ChannelSftp getClient() {
|
public ChannelSftp getClient() {
|
||||||
|
if(false == this.channel.isConnected()){
|
||||||
|
init();
|
||||||
|
}
|
||||||
return this.channel;
|
return this.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +259,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
@Override
|
@Override
|
||||||
public String pwd() {
|
public String pwd() {
|
||||||
try {
|
try {
|
||||||
return channel.pwd();
|
return getClient().pwd();
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -270,7 +273,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public String home() {
|
public String home() {
|
||||||
try {
|
try {
|
||||||
return channel.getHome();
|
return getClient().getHome();
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(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) {
|
public List<LsEntry> lsEntries(final String path, final Predicate<LsEntry> predicate) {
|
||||||
final List<LsEntry> entryList = new ArrayList<>();
|
final List<LsEntry> entryList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
channel.ls(path, entry -> {
|
getClient().ls(path, entry -> {
|
||||||
final String fileName = entry.getFilename();
|
final String fileName = entry.getFilename();
|
||||||
if (!StrUtil.equals(".", fileName) && !StrUtil.equals("..", fileName)) {
|
if (!StrUtil.equals(".", fileName) && !StrUtil.equals("..", fileName)) {
|
||||||
if (null == predicate || predicate.test(entry)) {
|
if (null == predicate || predicate.test(entry)) {
|
||||||
@ -376,7 +379,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.channel.mkdir(dir);
|
getClient().mkdir(dir);
|
||||||
return true;
|
return true;
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
@ -387,7 +390,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
public boolean isDir(final String dir) {
|
public boolean isDir(final String dir) {
|
||||||
final SftpATTRS sftpATTRS;
|
final SftpATTRS sftpATTRS;
|
||||||
try {
|
try {
|
||||||
sftpATTRS = this.channel.stat(dir);
|
sftpATTRS = getClient().stat(dir);
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
final String msg = e.getMessage();
|
final String msg = e.getMessage();
|
||||||
// issue#I4P9ED@Gitee
|
// issue#I4P9ED@Gitee
|
||||||
@ -415,7 +418,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
channel.cd(directory.replace('\\', '/'));
|
getClient().cd(directory.replace('\\', '/'));
|
||||||
return true;
|
return true;
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new FtpException(e);
|
throw new FtpException(e);
|
||||||
@ -430,7 +433,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
@Override
|
@Override
|
||||||
public boolean delFile(final String filePath) {
|
public boolean delFile(final String filePath) {
|
||||||
try {
|
try {
|
||||||
channel.rm(filePath);
|
getClient().rm(filePath);
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -450,6 +453,8 @@ public class Sftp extends AbstractFtp {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ChannelSftp channel = getClient();
|
||||||
|
|
||||||
final Vector<LsEntry> list;
|
final Vector<LsEntry> list;
|
||||||
try {
|
try {
|
||||||
list = channel.ls(channel.pwd());
|
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) {
|
public Sftp put(final String srcFilePath, final String destPath, final SftpProgressMonitor monitor, final Mode mode) {
|
||||||
try {
|
try {
|
||||||
channel.put(srcFilePath, destPath, monitor, mode.ordinal());
|
getClient().put(srcFilePath, destPath, monitor, mode.ordinal());
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(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) {
|
public Sftp put(final InputStream srcStream, final String destPath, final SftpProgressMonitor monitor, final Mode mode) {
|
||||||
try {
|
try {
|
||||||
channel.put(srcStream, destPath, monitor, mode.ordinal());
|
getClient().put(srcStream, destPath, monitor, mode.ordinal());
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -658,7 +663,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp get(final String src, final String dest) {
|
public Sftp get(final String src, final String dest) {
|
||||||
try {
|
try {
|
||||||
channel.get(src, dest);
|
getClient().get(src, dest);
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -675,7 +680,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp get(final String src, final OutputStream out) {
|
public Sftp get(final String src, final OutputStream out) {
|
||||||
try {
|
try {
|
||||||
channel.get(src, out);
|
getClient().get(src, out);
|
||||||
} catch (final SftpException e) {
|
} catch (final SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user