⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domdriver.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.xstream.io.xml;import com.thoughtworks.xstream.io.*;import org.w3c.dom.Document;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.FactoryConfigurationError;import javax.xml.parsers.ParserConfigurationException;import java.io.*;public class DomDriver implements HierarchicalStreamDriver {    private final String encoding;    private final DocumentBuilderFactory documentBuilderFactory;    public DomDriver(String encoding) {        documentBuilderFactory = DocumentBuilderFactory.newInstance();        this.encoding = encoding;    }    public DomDriver() {        this("UTF-8");    }    public HierarchicalStreamReader createReader(Reader xml) {        return createReader(new InputSource(xml));    }    public HierarchicalStreamReader createReader(InputStream xml) {        return createReader(new InputSource(xml));    }    private HierarchicalStreamReader createReader(InputSource source) {        try {            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();            source.setEncoding(encoding);            Document document = documentBuilder.parse(source);            return new DomReader(document);        } catch (FactoryConfigurationError e) {            throw new StreamException(e);        } catch (ParserConfigurationException e) {            throw new StreamException(e);        } catch (SAXException e) {            throw new StreamException(e);        } catch (IOException e) {            throw new StreamException(e);        }    }    public HierarchicalStreamWriter createWriter(Writer out) {        return new PrettyPrintWriter(out);    }    public HierarchicalStreamWriter createWriter(OutputStream out) {        return createWriter(new OutputStreamWriter(out));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -