Groovy says my Unicode string is too long

前端 未结 2 1136
青春惊慌失措
青春惊慌失措 2021-01-12 15:12

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 s

相关标签:
2条回答
  • 2021-01-12 15:44

    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.

    0 讨论(0)
  • 2021-01-12 15:56

    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)

    0 讨论(0)
提交回复
热议问题