Java spring集成-逐行读取远程文件
我正在尝试使用spring集成逐行读取远程文件。使用找到的spring文档,我已经设置了我的项目来轮询文件,并在找到文件时通过sftp传输它。我一直在思考如何一行一行地阅读文件内容 这是我的入站通道适配器设置,当前用于拉入文件Java spring集成-逐行读取远程文件,java,spring,spring-integration,Java,Spring,Spring Integration,我正在尝试使用spring集成逐行读取远程文件。使用找到的spring文档,我已经设置了我的项目来轮询文件,并在找到文件时通过sftp传输它。我一直在思考如何一行一行地阅读文件内容 这是我的入站通道适配器设置,当前用于拉入文件 <int-sftp:inbound-channel-adapter id="sftpAdapterAutoCreate" session-factory="sftpSessionFactory"
<int-sftp:inbound-channel-adapter id="sftpAdapterAutoCreate"
session-factory="sftpSessionFactory"
channel="receiveChannel"
filename-pattern="*.txt"
remote-directory="/home/springftp"
preserve-timestamp="true"
local-directory="file:C:\sprintftp"
auto-create-local-directory="true"
temporary-file-suffix=".writing"
delete-remote-files="false">
<int:poller fixed-rate="1000" max-messages-per-poll="1"/>
</int-sftp:inbound-channel-adapter>
<int:channel id="receiveChannel">
<int:queue/>
</int:channel>
编辑:为了澄清,我想从远程文件中一次检索一行,然后处理该行的内容,然后检索下一行。类似于为本地文件创建java.io.inputstream并逐行读取它
非常感谢您的帮助。谢谢大家! 您可以在接收文件后使用
和
将有效负载的内容限定到行列表中
更新
我想从远程文件中一次检索一行,然后处理该行的内容,然后检索下一行。类似于为本地文件创建java.io.inputstream并逐行读取它
不幸的是,我们没有为此提供高级组件,但您可以尝试使用RemoteFileTemplate
中的功能:
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<FTPFile>(this.ftpSessionFactory);
template.setFileNameExpression(new SpelExpressionParser().parseExpression("payload"));
template.setBeanFactory(mock(BeanFactory.class));
template.afterPropertiesSet();
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
template.get(new GenericMessage<String>("ftpSource/ftpSource1.txt"), new InputStreamCallback() {
@Override
public void doWithInputStream(InputStream stream) throws IOException {
FileCopyUtils.copy(stream, baos1);
}
});
RemoteFileTemplate=new RemoteFileTemplate(this.ftpSessionFactory);
setFileNameExpression(新的SpelExpressionParser().parseExpression(“有效负载”));
setBeanFactory(mock(BeanFactory.class));
template.afterPropertieSet();
final ByteArrayOutputStream=1=新ByteArrayOutputStream();
get(新的GenericMessage(“ftpSource/ftpSource1.txt”),新的InputStreamCallback(){
@凌驾
公共void doWithInputStream(InputStream流)引发IOException{
copyUtils.copy(流,1);
}
});
这段代码您可以连接到您的POJO服务,并将最后一段代码连接到
对不起,我应该澄清我的意图。我想从远程文件中一次检索一行,然后处理该行的内容,然后检索下一行。类似于为本地文件创建java.io.inputstream并逐行读取。@ArtemBilan我们不能使用带有-stream
选项的SFTP出站网关get
命令将文件作为流读取吗?