How can I convert a javax.xml.transform.Source into a InputStream? The Implementation of Source is javax.xml.transform.dom.DOMSource.
Source inputSource = messageContext.getRequest().getPayloadSource();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First try to downcast to
javax.xml.transform.stream.StreamSource. If that succeeds you have access to the underlyingInputStreamorReaderthrough getters. This would be the easiest way.If downcasting fails, you can try using a
javax.xml.transform.Transformerto transform it into ajavax.xml.transform.stream.StreamResultthat has been setup with ajava.io.ByteArrayOutputStream. Then you return ajava.io.ByteArrayInputStream. Something like:Of course, if the
StreamSourcecan be a large document, this is not advisable. In that case, you could use a temporary file andjava.io.FileOutputStream/java.io.FileInputStram. Another option would be to spawn a transformer thread and communicate throughjava.io.PipedOutputStream/java.io.PipedInputStream, but this is more complex: