tags:

views:

211

answers:

1

Hi,

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 OutputStreamWriter(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) ?

+1  A: 

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

Tony Nassar