发布时间:2025-12-09 11:56:48 浏览次数:1
import com.sun.org.apache.xerces.internal.impl.PropertyManager; //导入依赖的package包/类XMLStreamReader getXMLStreamReaderImpl(XMLInputSource inputSource) throws javax.xml.stream.XMLStreamException{ //1. if the temp reader is null -- create the instance and return if(fTempReader == null){ fPropertyChanged = false; return fTempReader = new XMLStreamReaderImpl(inputSource, new PropertyManager(fPropertyManager)); } //if factory is configured to reuse the instance & this instance can be reused //& the setProperty() hasn't been called if(fReuseInstance && fTempReader.canReuse() && !fPropertyChanged){ if(DEBUG)System.out.println("Reusing the instance"); //we can make setInputSource() call reset() and this way there wont be two function calls fTempReader.reset(); fTempReader.setInputSource(inputSource); fPropertyChanged = false; return fTempReader; }else{ fPropertyChanged = false; //just return the new instance.. note that we are not setting fTempReader to the newly created instance return fTempReader = new XMLStreamReaderImpl(inputSource, new PropertyManager(fPropertyManager)); }} import com.sun.org.apache.xerces.internal.impl.PropertyManager; //导入依赖的package包/类javax.xml.stream.XMLStreamWriter createXMLStreamWriter(javax.xml.transform.stream.StreamResult sr, String encoding) throws javax.xml.stream.XMLStreamException { //if factory is configured to reuse the instance & this instance can be reused //& the setProperty() hasn't been called try{ if(fReuseInstance && fStreamWriter != null && fStreamWriter.canReuse() && !fPropertyChanged){ fStreamWriter.reset(); fStreamWriter.setOutput(sr, encoding); if(DEBUG)System.out.println("reusing instance, object id : " + fStreamWriter); return fStreamWriter; } return fStreamWriter = new XMLStreamWriterImpl(sr, encoding, new PropertyManager(fPropertyManager)); }catch(java.io.IOException io){ throw new XMLStreamException(io); }} import com.sun.org.apache.xerces.internal.impl.PropertyManager; //导入依赖的package包/类/** * Creates a new instance of XMLStreamWriterImpl. Uses platform's default * encoding. * * @param outputStream Underlying stream to write the bytes to * @param props Properties used by this writer */public XMLStreamWriterImpl(OutputStream outputStream, PropertyManager props) throws IOException { // cannot call this(outputStream, null, props); for constructor, // OutputStreamWriter charsetName cannot be null // use default encoding this(new OutputStreamWriter(outputStream), props);}