2016-09-22 124 views
0

如何使用Spring集成寫入遠程文件Sftp Streaming。我使用xml獲得了一些代碼,但是我必須嚴格使用java配置,並且找不到任何。在驗證失敗後,我必須繼續向文件添加一些數據。因爲它不是一次性寫入/傳輸,但是我必須保持與遠程的連接,並且繼續使用錯誤日誌附加文件。任何幫助都會感激。使用Spring集成寫入遠程文件Sftp Streaming java配置

回答

2

使用SftpRemoteFileTemplate​​與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; 
}); 

寫入到輸出流(從另一個線程)將通過管道輸送到的輸入流。流關閉時傳輸將結束。

+0

我的意思是,還有誰能更好地回答這個問題? – arseniyandru

+0

「更好」是什麼意思?什麼不清楚? –

+0

對不起,對於題外話。這是一個修辭性的問題,因爲你是Spring Integration項目的領導者,所以你可能知道你在說什麼,但答案仍然不被接受。 – arseniyandru