@ SuppressWarnings ( "resource" ) private XMLStreamWriter2 createSW ( OutputStream out , Writer w , String enc , boolean requireAutoClose ) throws XMLStreamException { /* Need to ensure that the configuration object is not shared * any more; otherwise later changes via factory could be * visible half-way through output... */ WriterConfig cfg = mConfig . createNonShared ( ) ; XmlWriter xw ; boolean autoCloseOutput = requireAutoClose || mConfig . willAutoCloseOutput ( ) ; if ( w == null ) { if ( enc == null ) { enc = WstxOutputProperties . DEFAULT_OUTPUT_ENCODING ; } else { /* Canonical ones are interned, so we may have * normalized encoding already... */ if ( enc != CharsetNames . CS_UTF8 && enc != CharsetNames . CS_ISO_LATIN1 && enc != CharsetNames . CS_US_ASCII ) { enc = CharsetNames . normalize ( enc ) ; } } try { if ( enc == CharsetNames . CS_UTF8 ) { w = new UTF8Writer ( cfg , out , autoCloseOutput ) ; xw = new BufferingXmlWriter ( w , cfg , enc , autoCloseOutput , out , 16 ) ; } else if ( enc == CharsetNames . CS_ISO_LATIN1 ) { xw = new ISOLatin1XmlWriter ( out , cfg , autoCloseOutput ) ; } else if ( enc == CharsetNames . CS_US_ASCII ) { xw = new AsciiXmlWriter ( out , cfg , autoCloseOutput ) ; } else { w = new OutputStreamWriter ( out , enc ) ; xw = new BufferingXmlWriter ( w , cfg , enc , autoCloseOutput , out , - 1 ) ; } } catch ( IOException ex ) { throw new XMLStreamException ( ex ) ; } } else { // we may still be able to figure out the encoding: if ( enc == null ) { enc = CharsetNames . findEncodingFor ( w ) ; } try { xw = new BufferingXmlWriter ( w , cfg , enc , autoCloseOutput , null , - 1 ) ; } catch ( IOException ex ) { throw new XMLStreamException ( ex ) ; } } return createSW ( enc , cfg , xw ) ; }
Bottleneck factory method used internally ; needs to take care of passing proper settings to stream writer .