Here you can find the source of convertResult(StreamResult result, StringWriter writer)
private static void convertResult(StreamResult result, StringWriter writer)
//package com.java2s; /*// w w w .j av a2s .c o m * Copyright (c) 2016 wetransform GmbH * * All rights reserved. This program and the accompanying materials are made * available 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. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution. If not, see <http://www.gnu.org/licenses/>. * * Contributors: * wetransform GmbH <http://www.wetransform.to> */ import java.io.ByteArrayOutputStream; import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; public class Main { private static void convertResult(StreamResult result, StringWriter writer) { ByteArrayOutputStream baos = (ByteArrayOutputStream) result.getOutputStream(); writer.write(baos.toString()); } private static void convertResult(DOMResult result, StringWriter writer) throws TransformerFactoryConfigurationError { TransformerFactory txfFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = txfFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource resultSource = new DOMSource(result.getNode(), result.getSystemId()); StreamResult printer = new StreamResult(writer); transformer.transform(resultSource, printer); } catch (TransformerException e) { throw new RuntimeException(e.getMessage(), e); } } }