I have a requirement where i need to read a large EDI file from file system and pass that to the TN using routeXML service.
I can’t use the convertToValues service.
Could anyone please suggest a method for reading the file as a stream and then passing the data to TN.
Or use pub.file:getFile, with loadAs set to stream.
However, this only handles the first (and easiest) part of Nisha’s post: how to read the file as a stream.
The second part is the tough part: how to send EDI documents to TN via routeXML without using convertToValues. Since routeXML accepts a node (which must be an XML document) as its input and an EDI document is definitely not an XML document, you’ll have to write your own code to convert from EDI to something that routeXML can understand.
Why not just use convertToValue? It works, its modular (accepts multiple EDI document types), and its already built for you.
Using the getFile will only do when its a small file…i need to read large files using getFile as stream and then i am lost how to handle it without using convertToValues.
If the file is very large and the IS goes for a toss even after processing with ffiterator while convertToValues and or with Stream(streamToString), then I think splitting the file in small chunks and then validating ,routing and processing each chunk can be a way through to avoid loading of entire file. But I dont know how much can this be helpfull to nisha as splitting the the file into many smaller files would break the integrity of the records in file .
Just to clarify, streamToString will always load the complete file into memory. When using a stream for large file handling, it is important to not do anything that will read the entire stream of bytes into memory.
But with loadAS stream always help dealing performance issues isn’t? BTW,Is there any article that confirms streamToString loads into memory?
just incase.
Yes, loadAs stream is the right thing to do to avoid loading an entire file into memory.
But as soon as you do streamToString, it will read the stream until EOF and make a String object out of the bytes. streamToBytes also reads until end of stream.
From the wM docs for streamToBytes: “This service reads all of the bytes from stream until the end of file is reached…”
streamToString is in PSUtilities. You can review the source for that. It too reads until the end of the stream.