com.nepxion.discovery.plugin.configcenter.parser.xml.dom4j.Dom4JWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-config-center Show documentation
Show all versions of discovery-plugin-config-center Show documentation
Nepxion Discovery is an enhancement for Spring Cloud Discovery
package com.nepxion.discovery.plugin.configcenter.parser.xml.dom4j;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
public class Dom4JWriter {
public static Document createDocument() {
return DocumentHelper.createDocument();
}
public static String getText(Document document) throws IOException, UnsupportedEncodingException {
return getText(document, Dom4JConstant.ENCODING_UTF_8);
}
public static String getText(Document document, String charset) throws IOException, UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputFormat outputFormat = new OutputFormat(" ", true, charset);
try {
XMLWriter writer = new XMLWriter(baos, outputFormat);
writer.write(document);
baos.flush();
} catch (UnsupportedEncodingException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
if (baos != null) {
baos.close();
}
}
return baos.toString(charset);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy