I have a Java program (a war) that runs out of memory when manipulating a big XML file. The program is a REST API that returns the manipulated XML via a REST Controller.
First, the program gets an XML file from a remote URL.
Then it replaces the values of id
attributes.
Finally, it returns the new XML to the caller via the API controller.
What I get from the remote URL is a byte[]
body with XML data.
Then, I convert it to a String.
Next, I do a regexp search-replace on the whole string.
Then I convert it back to a byte[]
.
I'm guessing that the XML now is in memory 3 times (the incoming bytes, the string and the outgoing bytes).
I'm looking for ways to improve this.
I have no local copies on the filesystem btw.