From 532d0a479e81a6054d84a1eda3b0af9e460d2595 Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Sat, 9 Feb 2002 00:52:09 +0000 Subject: [PATCH] - Add an helper method to write directly a document as UTF8 from a stream. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271231 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/util/DOMElementWriter.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/DOMElementWriter.java b/src/main/org/apache/tools/ant/util/DOMElementWriter.java index c0fd6089e..2ce596c33 100644 --- a/src/main/org/apache/tools/ant/util/DOMElementWriter.java +++ b/src/main/org/apache/tools/ant/util/DOMElementWriter.java @@ -56,6 +56,9 @@ package org.apache.tools.ant.util; import java.io.IOException; import java.io.Writer; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Attr; @@ -73,7 +76,7 @@ import org.w3c.dom.Text; * * @author The original author of XmlLogger * @author Stefan Bodewig - * @author Stephane Bailliez + * @author Stephane Bailliez */ public class DOMElementWriter { @@ -85,15 +88,30 @@ public class DOMElementWriter { * entities. */ protected String[] knownEntities = {"gt", "amp", "lt", "apos", "quot"}; - + + + /** + * Writes a DOM tree to a stream in UTF8 encoding. Note that + * it appends the <?xml version='1.0' encoding='UTF-8'?>. + * The indent number is set to 0 and a 2-space indent. + * @param root the root element of the DOM tree. + * @param out the outputstream to write to. + * @throws IOException if an error happens while writing to the stream. + */ + public void write(Element root, OutputStream out) throws IOException { + Writer wri = new OutputStreamWriter(out, "UTF8"); + wri.write("\n"); + write(root, wri, 0, " "); + wri.flush(); + } + /** * Writes a DOM tree to a stream. - * * @param element the Root DOM element of the tree * @param out where to send the output * @param indent number of - * @param indentWith strings, - * that should be used to indent the corresponding tag. + * @param indentWith string that should be used to indent the corresponding tag. + * @throws IOException if an error happens while writing to the stream. */ public void write(Element element, Writer out, int indent, String indentWith)