本文整理匯總了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);
}
}
}