code: public static StreamingOutput createStream(final Document doc) {
          return new StreamingOutput() {
  
              @Override
              public void write(final OutputStream output) {
                  synchronized (output) {
                      final DOMSource domSource = new DOMSource(doc);
                      final StreamResult streamResult = new StreamResult(output);
                      Transformer transformer;
                      try {
                          transformer = TransformerFactory.newInstance().newTransformer();
                          transformer.transform(domSource, streamResult);
                      } catch (final TransformerException exc) {
                          exc.printStackTrace();
                          throw new JaxRxException(exc);
                      }
  
                  }
              }
          };
      }
docs: Creates an output stream from the specified document.
  
  @param doc
  document input
  @return output stream