// try to reuse
try {
resetMethod.invoke(xsw);
setOutputMethod.invoke(xsw,new StreamResult(out),encoding);
} catch (IllegalAccessException e) {
throw new XMLReaderException("stax.cantCreate",e);
} catch (InvocationTargetException e) {
throw new XMLReaderException("stax.cantCreate",e);
}
} else {
// create a new instance
try {
xsw = xof.createXMLStreamWriter(out,encoding);
} catch (XMLStreamException e) {
throw new XMLReaderException("stax.cantCreate",e);
}
}
return new HasEncodingWriter(xsw, encoding);
}