當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLWriter.flush方法代碼示例

本文整理匯總了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;
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:29,代碼來源:HttpClient.java

示例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();
}
 
開發者ID:kkrugler,項目名稱:yalder,代碼行數:26,代碼來源:WikipediaCrawlTool.java

示例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;
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:18,代碼來源:QTIExportImportTest.java

示例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;
		}
	}
}
 
開發者ID:micromagic,項目名稱:eterna,代碼行數:26,代碼來源:MemoryLogger.java

示例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;
	}
}
 
開發者ID:micromagic,項目名稱:eterna,代碼行數:23,代碼來源:BaseDao.java

示例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;
	}
}
 
開發者ID:micromagic,項目名稱:eterna,代碼行數:19,代碼來源:AppData.java

示例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();
  }
}
 
開發者ID:thinkberg,項目名稱:snipsnap,代碼行數:17,代碼來源:XMLSnipExport.java

示例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());
    }
  }
 
開發者ID:thinkberg,項目名稱:snipsnap,代碼行數:27,代碼來源:JDBCDatabaseExport.java

示例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);
    }
}
 
開發者ID:frankelau,項目名稱:pndao,代碼行數:31,代碼來源:DaoGenHelper.java

示例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());
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:34,代碼來源:PermissionModel.java

示例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();	
}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:16,代碼來源:Dom4jHelper.java

示例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);
}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:20,代碼來源:Dom4jHelper.java

示例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();
}
 
開發者ID:yi-jun,項目名稱:aaden-pay,代碼行數:29,代碼來源:LianlianBranchTest.java

示例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() );
	}

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:XMLHelper.java

示例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);
        }
    }
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:16,代碼來源:XmlClobType.java


注:本文中的org.dom4j.io.XMLWriter.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。