Is groovy.xml.XmlUtil.serialize method buggy for large streams of xml input?

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))

      

XML export file truncated !!

If instead I do the following:

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

      

Then the resulting file looks as expected, but not in xml format.

So my questions are:

1- Is this a bug for XmlUtil.serialize

, related to large XML streaming, or do I need to adjust the max buffer somewhere?

2. Do you know a workaround for xml formatting an object StreamingMarkupBuilder

? (code examples are welcome)?

+2


source to share


1 answer


Instead of <for Writer, you should use File # withWriter () method to make sure Writer is closed correctly!



+1


source







All Articles