Groovy says my Unicode string is too long

荒凉一梦 提交于 2019-12-01 04:44:54

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!