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).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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).