I need to convert a DOMSource
to a StreamSource
, because a third-party library only accepts stream sources for SOAP.
In this case, performance is not so much a problem, so I came up with this terribly detailed set of commands:
DOMSource src = new DOMSource(document); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); StreamResult result = new StreamResult(); ByteArrayOutputStream out = new ByteArrayOutputStream(); result.setOutputStream(out); transformer.transform(src, result); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); StreamSource streamSource = new StreamSource(in);
Is there an easier way to do this?
source share