spring integration - read a remote file line by line

对着背影说爱祢 提交于 2019-12-02 09:12:44

You can use <file-to-string-transformer> after the receiving File and <splitter> to delimit the content of payload to the list of lines.

UPDATE

I would like to retrieve one line at a time from the remote file, then process the contents of that line, then retrieve the next line. Similar to creating a java.io.inputstream for a local file and reading it line by line.

Well, Unfortunatelly we don't provide high-level component for that, but you can try to use the features from the 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);
    }
});

This code you can to some your POJO service and wire the last one with <service-activator>.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!