views:

109

answers:

1

It's my first time posing a question here. I would like to know which constructor is better in terms of performance for a large xml dom to be written to a test.xml file:

new StreamResult(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("test.xml"), "UTF-8")))

Or

new StreamResult(new FileOutputStream("test.xml"))

Regarding setting the UTF-8 encoding, what happens in the second case where it's not specified for an OutputStream? (Edit: This is answered but not the performance part yet)

StreamResult Constructor JavaDoc Link

Thanks

+1  A: 

Encoding is done through Transformer. The Transformer may use instructions contained in the transformation instructions to control the encoding.

adatapost
+1. Which is why it's generally preferred to use `new StreamResult(OutputStream))` constructor. BufferedWriter should not make a big difference, but if you're so concerned about performance - measure it for both cases and choose the better one.
ChssPly76