spring integration - read a remote file line by line

后端 未结 1 946
鱼传尺愫
鱼传尺愫 2021-01-28 17:12

I am trying to read a remote file line by line, using spring integration. Using the spring documentation found here I have set up my project to poll for the file and transfer it

相关标签:
1条回答
  • 2021-01-28 18:07

    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>.

    0 讨论(0)
提交回复
热议问题