开发者

Is the method groovy.xml.XmlUtil.serialize buggy for big xml input streaming?

When I execute the following script:

mb = new groovy.xml.StreamingMarkupBuilder()
mb.encoding = "UTF-8"
xmlClosure = {...} //BIG XML File building (at least 300 KB)

new OutputStreamWriter(new FileOutputStream(exportXmlFile), 'utf-8') << groovy.xml.XmlUtil.serialize(mb.bind(xmlClosure))

The XML export file is truncated!!

If instead, I execute the following :

new OutputStreamWri开发者_高级运维ter(new FileOutputStream(exportXmlFile), 'utf-8') << mb.bind(xmlClosure)

Then the resulting file is as expected but not xml-formatted.

So my questions are:

1- Is it a bug for XmlUtil.serialize dealing with big XML streaming or do I need to configure somewhere a maximum buffer?

2- Do you know a workaround for xml-formatting a StreamingMarkupBuilder object ? (code examples are welcomed) ?


Rather than << to the Writer, you should use the File#withWriter() method to ensure that the Writer is closed properly!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜