Writing to a remote file using Spring Integrations Sftp Streaming java configuration

北城以北 提交于 2019-12-25 16:42:06

问题


How to write to a remote file using Spring integrations Sftp Streaming .I got some code using xml but I have to strictly use java configuration and I cant find any . I have to keep on appending some data to the file after some validation failure.So its not a one time write/transfer but I have to maintain the connection with remote and keep on appending the file with error logs.Any help appreciated.


回答1:


Use an SftpRemoteFileTemplate execute() with a SessionCallback ...

SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sessionFactory);
PipedInputStream pipe = new PipedInputStream();
OutputStream outputStream = new PipedOutputStream(pipe);
template.execute(s -> {
    s.write(pipe, "/foo/bar.log");
    return null;
});

Writing to the output stream (from another thread) will be piped to the input stream. Transfer will end when the stream is closed.



来源:https://stackoverflow.com/questions/39630475/writing-to-a-remote-file-using-spring-integrations-sftp-streaming-java-configura

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