当前位置: 首页>>代码示例>>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;未经允许,请勿转载。