I\'m getting a java outOfMemoryError when I call this method - i\'m using it in a loop to parse many large files in sequence. my guess is that result.toString()
I reckon the problem with StringBuilder.append()
. When Matcher appends sequence of characters to the Builder.
As explained in article about OutOfMemoryError with StringBuilder/StringBuffer, it is a known issue that append() will double the capacity if internal buffer chars
if the capacity is not sufficient.
Go for streams as suggested by Erickson.