I am attempting to process a file exactly like this question: read a remote file line by line
The one answer to this question suggests to use RemoteFileTemplate but I am attempting to use the -stream option as suggested in the last comment to the answer. Also, this kinda seems like the point of the -stream option; to get a stream.
My implementation successfully obtains the InputStream and kick off a separate thread to process in a BufferedReader.
This works happily on windows laptop but deployment on a linux machine I sometimes get a "Write end dead" exception caught when trying to read the BufferedReader in my processing thread.
Research into this suggests the writer is not closing the stream properly: Write end dead exception using PipedInputStream
So, either this is a bug in spring-integration or there is something missing in my configuration. I am hoping it is the latter and could use feedback on the way I am obtaining the InputStream. If I am getting the InputStream correctly, then how can I get the writer to close the input stream after writing?
Thanks!
Here is outbound gateway configuration:
<int-ftp:outbound-gateway session-factory="ftpClientFactory"
request-channel="inboundGetStream" command="get" command-options="-stream"
expression="payload" remote-directory="/" reply-channel="stream">
</int-ftp:outbound-gateway>
<int:channel id="stream">
<int:queue/>
</int:channel>
Here is where I obtain the InputStream:
public InputStream openFileStream(final String filename, final String directory) throws Exception {
if (inboundGetStream.send(MessageBuilder.withPayload(directory + "/" + filename).build(), ftpTimeout)) {
return getInputStream();
}
return null;
}
private InputStream getInputStream() {
Message<?> msgs = stream.receive(ftpTimeout);
if (msgs == null) {
return null;
}
InputStream is = (InputStream) msgs.getPayload();
return is;
}