As part of my probably wrong and cumbersome solution to print out a form I have taken a MS-Word document, saved as XML and I'm trying to store that XML as a groovy string so that I can ${fillOutTheFormProgrammatically}
However, with MS-Word documents being as large as they are, the String is 113100 unicode characters and Groovy says its limited to 65536. Is there some way to change this or am I stuck with splitting up the string?
Groovy - need to make a printable form
That's what I'm trying to do.
Update: to be clear its too long of a Groovy String.. I think a regular string might be all good. Going to change strategy and put some strings in the file I can easily find like %!%variable_name%!% and then do .replace(... uh i feel a new question coming on here...
Are you embedding this string directly in your groovy code? The jvm itself has a limit on the length of string constants, see the VM Spec if you are interested in details.
A ugly workaround might be to split the string in smaller parts and concatenate them at runtime. A better solution would be to save the text in an external file and read the contents from your code. You could also package this file along with your code and access it from the classpath using Class#getResourceAsStream.
What exception are you getting? I don't believe Groovy String is limited to 65536, as it is basically a Java string.
Sounds to me like you are trying to recurse somewhere and hitting the 65536 call stack limit.
That being said however, loading a 100K+ char into memory in one go does seem like overkill..
Why not parse the XML using a SAX parser or similar to get the results out?
Or why not save just the data you need to start with rather than relying on hunderds of thousands of chars of xml (which I assume you only want a small section of)
来源:https://stackoverflow.com/questions/6835798/groovy-says-my-unicode-string-is-too-long