Here you can find the source of castResultToSource(StreamResult result)
public static StreamSource castResultToSource(StreamResult result)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.StringReader; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class Main { public static StreamSource castResultToSource(StreamResult result) { StreamSource ss = new StreamSource(new StringReader(result.getWriter().toString())); String systemId = result.getSystemId(); if (systemId != null) { ss.setSystemId(new File(systemId)); }//from w w w. j a va 2 s . c o m return ss; } }