How can I use SimpleTemplateEngine or GStringTemplateEngine to process a template larger than 65535 characters?
I receive the following error:
groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript1.groovy: 5614: String too long. The given string is 198495 Unicode code units long, but only a maximum of 65535 is allowed.
I'm building the template using the following code:
def templateEngine = new SimpleTemplateEngine()
def binding = [:]
templateEngine
.createTemplate(new FileReader("input.txt))
.make(binding)
.writeTo(new FileWriter(new File("output.txt")))
I found JIRA 3487 related to this issue: GStringTemplateEngine fails to work with >64K strings .
I've thought about chunking the input but that brings it's own complications like making sure not to break in the middle of an expression.
I would appreciate any other suggestions.
Found some replacements for GStringTemplateEngine
These can can handle large Strings.
https://github.com/mbjarland/groovy-streaming-template-engine
https://github.com/mbknor/gt-engine
Try using a GStringTemplateEngine
instead. From the javadoc:
Processes template source files substituting variables and expressions into placeholders in a template source text to produce the desired output using a streaming approach. This engine has equivalent functionality to the SimpleTemplateEngine but creates the template using writable closures making it potentially more scalable for large templates or in streaming scenarios.
You will probably get away with simply replacing new SimpleTemplateEngine()
with new GStringTemplateEngine()
, but should of course test it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With