In some cases the high CPU is a result of string concatination. So, if you have your large file and are creating a string with that using the string = string1 + string2, or string1 = string1 + string2 syntax you will see degrading performances as the string gets larger and larger. This is a known behavior with java.
When dealing with larger strings, it is recommended that you use the java StringBuilder object. This allows you to concatinate large strings in an efficient manner.
So, if we have the following script:
var data = "prefixData" + fileContents + "suffixData";
data = data + "moreContent";
We can change it to this:
var stringBuilder = new java.lang.StringBuilder();
stringBuilder.append("prefixData").append(fileContents);
stringBuilder.append("suffixData").append("moreContent");
var data = stringBuilder.toString();
The StringBuilder approach will be much more efficient at concatinating a large string and will use a lot less CPU to process.