本文整理汇总了Java中javax.xml.transform.stream.StreamResult.getWriter方法的典型用法代码示例。如果您正苦于以下问题:Java StreamResult.getWriter方法的具体用法?Java StreamResult.getWriter怎么用?Java StreamResult.getWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.stream.StreamResult
的用法示例。
在下文中一共展示了StreamResult.getWriter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: StreamSerializer
import javax.xml.transform.stream.StreamResult; //导入方法依赖的package包/类
public StreamSerializer(StreamResult streamResult) {
// if this method opened a stream, let it close it
final OutputStream[] autoClose = new OutputStream[1];
if (streamResult.getWriter() != null)
writer = createWriter(streamResult.getWriter());
else if (streamResult.getOutputStream() != null)
writer = createWriter(streamResult.getOutputStream());
else if (streamResult.getSystemId() != null) {
String fileURL = streamResult.getSystemId();
fileURL = convertURL(fileURL);
try {
FileOutputStream fos = new FileOutputStream(fileURL);
autoClose[0] = fos;
writer = createWriter(fos);
} catch (IOException e) {
throw new TxwException(e);
}
} else
throw new IllegalArgumentException();
// now delegate to the SaxSerializer
serializer = new SaxSerializer(writer,writer,false) {
public void endDocument() {
super.endDocument();
if(autoClose[0]!=null) {
try {
autoClose[0].close();
} catch (IOException e) {
throw new TxwException(e);
}
autoClose[0] = null;
}
}
};
}
示例2: setOutput
import javax.xml.transform.stream.StreamResult; //导入方法依赖的package包/类
/**
* Use a StreamResult to initialize the output for this XMLStreamWriter. Check
* for OutputStream, Writer and then systemId, in that order.
*
* @param sr StreamResult encapsulating output information
* @param encoding Encoding to be used except when a Writer is available
*/
public void setOutput(StreamResult sr, String encoding)
throws IOException {
if (sr.getOutputStream() != null) {
setOutputUsingStream(sr.getOutputStream(), encoding);
}
else if (sr.getWriter() != null) {
setOutputUsingWriter(sr.getWriter());
}
else if (sr.getSystemId() != null) {
setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
encoding);
}
}