String encoding = null;
boolean requireAutoClose;
String sysId = null;
if (res instanceof Stax2Result) {
Stax2Result sr = (Stax2Result) res;
try {
out = sr.constructOutputStream();
if (out == null) {
w = sr.constructWriter();
}
} catch (IOException ioe) {
throw new WstxIOException(ioe);
}
// yes, it's required since caller has no access to stream/writer:
requireAutoClose = true;
} else if (res instanceof StreamResult) {
StreamResult sr = (StreamResult) res;
out = sr.getOutputStream();
sysId = sr.getSystemId();
if (out == null) {
w = sr.getWriter();
}
/* Caller owns it, only auto-close if requested to do so:
* (except that for system-id-only, it'll still be required,
* see code below)
*/
requireAutoClose = false;
} else if (res instanceof SAXResult) {
SAXResult sr = (SAXResult) res;
sysId = sr.getSystemId();
if (sysId == null || sysId.length() == 0) {
throw new XMLStreamException("Can not create a stream writer for a SAXResult that does not have System Id (support for using SAX input source not implemented)");
}
requireAutoClose = true;
} else if (res instanceof DOMResult) {