I’m designing a gateway service to extract information from a file and then route it to Trading Networks. If I read in the file as a stream using pub.file:getFile and extract the information I need, I have to call the getFile service again to get a stream I can map to wm.tn.doc.ff:routeFlatFile. If I just map the object that’s already in the pipeline I get a ‘no valid records found’ exception.
This must be because of the nature of the stream object, which I’m not too familiar with. Is there a better or more efficient way of doing this? Thanks.
Hello,
A stream is a buffer, and when you read, you move the pointer along the stream until the end. To use the same stream again, you will have to rewind the pointer to the beginning of the stream. java.io.ByteArrayInputStream seams to such the mark, read, and reset methods to allow you to reuse a stream. You will have to handle those operations in a separate service. You can pass in the stream to a mark service, then do your normal reading. When you are done, you can pass it into a reset service. Streams are for ease on memory and Strings are for ease of manipulation (relatively). Good day.
Thanks for the information. I was able to use the io services in the WmFlatFile package in a way similar to your description. Also, before I saw this reply, I dropped the original stream after doing convertToValues and then did a convertToString and stringToStream to make the call to routeFlatFile. I suspect that reusing a single stream using the pointer is more efficient, however. Thanks again,
This post helped me solve a problem I encountered when sending a MIME email. By applying the pub.io.reset service in WmFlatFile package to my java.io.ByteArrayInputStream that contained the MIME data, I was able to loop over a String list of to: email addresses and send the HTML email to multiple recipients.