DEV Community

Discussion on: Navigating the uncharted Stream

Collapse
 
lluismf profile image
Lluís Josep Martínez

Check accepted answer in stackoverflow.com/questions/285045... it's basically what you need, with less boilerplate and faster.

Collapse
 
eldroskandar profile image
Bastien Helders • Edited

Still I think I'll need to use a Supplier, as I'll have to loop through the Lists or better through a Map to change each placeholder with their corresponding values.

Furthermore, I will then still use a loop to loop through the Map entries which will make me write the file anew for each of the entries. Unless I'm missing something, which probably could be, I don't think this would be efficient.

Collapse
 
lluismf profile image
Lluís Josep Martínez

If you want to get rid of the loop (whatever the reason) I guess you need to change the input values. Instead of 2 lists, use a single collection of KeyValue objects or a Map. And you would be able to use map and a closure to perform the replacement.

Regarding efficiency, if the input file is small no problem. But if it's in the order of gigabytes, converting the Stream to String needs to allocate a huge array of bytes in the heap and you risk an out of memory. Writing to the output file as a stream OTOH will be efficient - in memory terms (not CPU).