Groovy说我的Unicode字符串太长了 [英] Groovy says my Unicode string is too long

查看:720
本文介绍了Groovy说我的Unicode字符串太长了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我打印出一份表格的可能错误和麻烦的解决方案的一部分,我采用了一个MS-Word文档,保存为XML,并且试图将该XML存储为一个常规字符串,以便我可以$ {fillOutTheFormProgrammatically}然而,MS-Word文档的大小与字符串一样大,字符串是113100个Unicode字符,而Groovy则将其限制为65536.有没有什么方法可以改变这种情况或者我坚持分裂字符串?



Groovy - 需要制作一个可打印的表单



这就是我想要做的。



更新:要清除Groovy字符串的太长时间..我认为一个常规字符串可能会很好。要改变策略,并在文件中放入一些字符串,我可以很容易地找到像%!%variable_name%!%然后做.replace(...呃,我觉得这里有一个新问题...

解决方案

您是否将该字符串直接嵌入到groovy代码中?jvm本身对字符串常量的长度有限制,请参阅 VM Spec ,如果你对细节感兴趣。



丑陋的解决方法可能是将字符串拆分成较小的部分,并在运行时连接它们。更好的解决方案是将文本保存在外部文件中并从代码中读取内容。你也可以将这个文件与你的代码一起打包,并使用 Class#getResourceAsStream


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.

这篇关于Groovy说我的Unicode字符串太长了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆