如何解决将文件写入服务器后,SftpRemoteFileTemplate 未退出方法
SftpConfigClass
@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(sftpPort);
factory.setUser(sftpUser);
factory.setPassword(Crypt.decrypt(decrptKey.trim(),sftpPasword.trim()));
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<>(factory);
}
测试类
@Autowired
private SftpConfig sftp;
@Test
public void sampleTest1() throws IOException {
String fileName = "FILE_NAME";
String dir = "/path/to/generate/file" + fileName;
SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sftp.sftpSessionFactory());
PipedInputStream pipe = new PipedInputStream();
OutputStream outputStream = new PipedOutputStream(pipe);
template.execute(s -> {
s.write(pipe,dir);
return null;
});
System.out.println("CLOSED------------------");
}
运行测试后,文件正在生成,但测试未完成,这意味着会话未退出且 template.execute 未退出且“CLOSED”未打印。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。