Here you can find the source of save(Node doc, OutputStream stream, String encoding, boolean indent)
private static void save(Node doc, OutputStream stream, String encoding, boolean indent) throws IOException
//package com.java2s; /* /*from w w w . j av a2 s . c o m*/ * This file is part of DISMOD Core. * ? Copyright 2003-2011 Fraunhofer Institut f. Materialfluss und Logistik. * http://www.iml.fraunhofer.de, http://www.verkehrslogistik.de * * DISMOD Core is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DISMOD Core is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with DISMOD Core. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Node; public class Main { private static void save(Node doc, OutputStream stream, String encoding, boolean indent) throws IOException { save(doc, stream, encoding, indent, null, null); } private static void save(Node doc, OutputStream stream, String encoding, boolean indent, String publicDocType, String systemDocType) throws IOException { try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); transformer.setOutputProperty(OutputKeys.ENCODING, encoding); if (publicDocType != null) transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, publicDocType); if (systemDocType != null) transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemDocType); StreamResult result = new StreamResult(stream); DOMSource source = new DOMSource(doc); transformer.transform(source, result); } catch (Exception e) { throw new IOException("Failure while writing dom result.", e); } } @SuppressWarnings("resource") public static void save(Node doc, File file) throws IOException { save(doc, new FileOutputStream(file), "ISO-8859-1", true); } public static void save(Node doc, OutputStream stream) throws IOException { save(doc, stream, "ISO-8859-1", true); } public static void save(Node doc, OutputStream stream, String encoding) throws IOException { save(doc, stream, encoding, true); } public static void save(Node doc, OutputStream stream, String encoding, String publicDocType, String systemDocType) throws IOException { save(doc, stream, encoding, true, publicDocType, systemDocType); } }