本文整理汇总了Java中org.dom4j.io.XMLWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Java XMLWriter.flush方法的具体用法?Java XMLWriter.flush怎么用?Java XMLWriter.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.io.XMLWriter
的用法示例。
在下文中一共展示了XMLWriter.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatXML
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* 格式化XML
*
* @param inputXML
* @return
* @throws Exception
*/
public static String formatXML(String inputXML) throws Exception {
Document doc = DocumentHelper.parseText(inputXML);
StringWriter out = null;
if (doc != null) {
try {
OutputFormat format = OutputFormat.createPrettyPrint();
out = new StringWriter();
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
return out.toString();
}
return inputXML;
}
示例2: formatXml
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* Returns the given xml document as nicely formated string.
*
* @param node
* The xml document.
* @return the formated xml as string.
*/
private static String formatXml(Node node) {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndentSize(4);
format.setTrimText(true);
format.setExpandEmptyElements(true);
StringWriter stringWriter = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(stringWriter, format);
try {
xmlWriter.write(node);
xmlWriter.flush();
} catch (IOException e) {
// this should never happen
throw new RuntimeException(e);
}
return stringWriter.getBuffer().toString();
}
示例3: exportAndImportToQTIFormat
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
private static QTIDocument exportAndImportToQTIFormat(QTIDocument qtiDocOrig) throws IOException {
Document qtiXmlDoc = qtiDocOrig.getDocument();
OutputFormat outformat = OutputFormat.createPrettyPrint();
String fileName = qtiDocOrig.getAssessment().getTitle() + "QTIFormat.xml";
OutputStreamWriter qtiXmlOutput = new OutputStreamWriter(new FileOutputStream(new File(TEMP_DIR, fileName)), Charset.forName("UTF-8"));
XMLWriter writer = new XMLWriter(qtiXmlOutput, outformat);
writer.write(qtiXmlDoc);
writer.flush();
writer.close();
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
Document doc = xmlParser.parse(new FileInputStream(new File(TEMP_DIR, fileName)), true);
ParserManager parser = new ParserManager();
QTIDocument qtiDocRestored = (QTIDocument) parser.parse(doc);
return qtiDocRestored;
}
示例4: printLog
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* 打印日志信息.
*
* @param out 打印日子的输出流
* @param clear 是否需要清空现有的日志
*/
public void printLog(Writer out, boolean clear)
throws IOException
{
if (this.logDocument == null)
{
return;
}
synchronized (this)
{
XMLWriter writer = new XMLWriter(out);
writer.write(this.logDocument);
writer.flush();
if (clear)
{
logDocument = null;
logNodes = null;
}
}
}
示例5: printLog
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* 将记录的日志输出.
*
* @param out 日志的输出流
* @param clear 是否要在输出完后清空日志
*/
public static synchronized void printLog(Writer out, boolean clear)
throws IOException
{
if (logDocument == null)
{
return;
}
XMLWriter writer = new XMLWriter(out);
writer.write(logDocument);
writer.flush();
if (clear)
{
logDocument = null;
logs = null;
}
}
示例6: printLog
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* 打印app运行日志信息
*/
public static synchronized void printLog(Writer out, boolean clear)
throws IOException
{
if (logDocument == null)
{
return;
}
XMLWriter writer = new XMLWriter(out);
writer.write(logDocument);
writer.flush();
if (clear)
{
logDocument = null;
}
}
示例7: store
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public static void store(OutputStream out, List snips, List users, String filter, List ignoreElements, File fileStore) {
try {
OutputFormat outputFormat = new OutputFormat();
outputFormat.setEncoding("UTF-8");
outputFormat.setNewlines(true);
XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
Element root = DocumentHelper.createElement("snipspace");
xmlWriter.writeOpen(root);
storeUsers(xmlWriter, users);
storeSnips(xmlWriter, snips, filter, ignoreElements, fileStore);
xmlWriter.writeClose(root);
xmlWriter.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: store
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* Store snips and users from the SnipSpace to an xml document into a stream.
* @param out outputstream to write to
*/
public static void store(OutputStream out, String appOid, Connection connection) {
try {
OutputFormat outputFormat = new OutputFormat();
outputFormat.setEncoding("UTF-8");
outputFormat.setNewlines(true);
XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
xmlWriter.startDocument();
Element root = DocumentHelper.createElement("snipspace");
xmlWriter.writeOpen(root);
// storeUsers(xmlWriter, connection);
storeSnips(xmlWriter, appOid, connection);
xmlWriter.writeClose(root);
xmlWriter.endDocument();
xmlWriter.flush();
xmlWriter.close();
} catch (Exception e) {
System.err.println("JDBCDatabaseExport: error while writing document: " + e.getMessage());
}
}
示例9: mixMethodToData
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public String mixMethodToData(DaoGen daoGen, String namespace, Map<String, MapperMethod> methodMap, String data) {
if (data.isEmpty())
data = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"\n" +
"<!DOCTYPE mapper\n" +
"PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n" +
"\n" +
"<mapper namespace=\"" + namespace + "\">\n" +
"</mapper>\n";
try {
Document document = parseText(data);
Element element = document.getRootElement();
element.elements().forEach(sqlEle -> {
String id = sqlEle.attribute("id").getText();
methodMap.remove(id);
});
methodMap.forEach(getGenFunc(daoGen, element));
OutputFormat format = OutputFormat.createPrettyPrint();
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
XMLWriter writer = new XMLWriter(outputStream, format);
writer.write(document);
writer.flush();
return outputStream.toString("UTF-8");
}
} catch (DocumentException | IOException | SAXException e) {
throw new Error(e);
}
}
示例10: processModelDocType
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
private InputStream processModelDocType(InputStream is, String dtdSchemaUrl) throws DocumentException, IOException
{
SAXReader reader = new SAXReader();
// read document without validation
Document doc = reader.read(is);
DocumentType docType = doc.getDocType();
if (docType != null)
{
// replace DOCTYPE setting the full path to the xsd
docType.setSystemID(dtdSchemaUrl);
}
else
{
// add the DOCTYPE
docType = new DefaultDocumentType(doc.getRootElement().getName(), dtdSchemaUrl);
doc.setDocType(docType);
}
ByteArrayOutputStream fos = new ByteArrayOutputStream();
try
{
OutputFormat format = OutputFormat.createPrettyPrint(); // uses UTF-8
XMLWriter writer = new XMLWriter(fos, format);
writer.write(doc);
writer.flush();
}
finally
{
fos.close();
}
return new ByteArrayInputStream(fos.toByteArray());
}
示例11: save
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* 保存文档
* @param doc
* @param xmlPath
* @param encoding
* @throws Exception
*/
public static void save(Document doc,String xmlPath,String encoding)throws Exception{
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding(encoding);
XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(xmlPath),encoding),format);
writer.write(doc);
writer.flush();
writer.close();
}
示例12: toString
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
* xml转换为字符串
* @param doc
* @param encoding
* @return
* @throws Exception
*/
public static String toString(Document doc,String encoding)throws Exception{
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding(encoding);
ByteArrayOutputStream byteOS=new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(new OutputStreamWriter(byteOS,encoding),format);
writer.write(doc);
writer.flush();
writer.close();
writer=null;
return byteOS.toString(encoding);
}
示例13: writeXml
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
private void writeXml(List<JSONArray> list) throws Exception {
File file = new File(SAVE_PATH);
if (file.exists())
file.delete();
// 生成一个文档
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root");
for (JSONArray jsonArray : list) {
for (Object object : jsonArray) {
JSONObject json = (JSONObject) object;
System.out.println(json);
Element element = root.addElement("branch");
// 为cdr设置属性名和属性值
element.addAttribute("branchId", json.getString("prcptcd").trim());// 支行行号
element.addAttribute("bankCode", json.getString("bankCode").trim());// 银行类型
element.addAttribute("cityCode", json.getString("cityCode").trim());// 城市代码
element.addAttribute("branchName", json.getString("brabank_name").trim());// 支行名称
}
}
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(new File(SAVE_PATH)), "UTF-8"), format);
// 写入新文件
writer.write(document);
writer.flush();
writer.close();
}
示例14: dump
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public static void dump(Element element) {
try {
// try to "pretty print" it
OutputFormat outFormat = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter( System.out, outFormat );
writer.write( element );
writer.flush();
System.out.println( "" );
}
catch ( Throwable t ) {
// otherwise, just dump it
System.out.println( element.asXML() );
}
}
示例15: nullSafeSet
import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
if (value == null) {
ps.setNull(index, sqlTypes()[0]);
} else {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(bytes,OutputFormat.createCompactFormat());
writer.write((Document)value);
writer.flush(); writer.close();
ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
} catch (IOException e) {
throw new HibernateException(e.getMessage(),e);
}
}
}