@Test public void writesDOMSourceToOutputStream() throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(TEST_XML_CONTENT_BYTES)); ByteArrayOutputStream out = new ByteArrayOutputStream(); domSourceEntityProvider.writeTo(new DOMSource(document), DOMSource.class, null, null, APPLICATION_XML_TYPE, null, out); Document serializedDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(out.toByteArray())); assertThatXmlDocumentContainsAllExpectedNodes(serializedDocument); }
@Override public void writeTo(DOMSource domSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(domSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }
DOMSourceEntityProvider implements EntityProvider<DOMSource> { @Override public void writeTo(DOMSource domSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(domSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } } }
DOMSourceEntityProvider implements EntityProvider<DOMSource> { @Override public void writeTo(DOMSource domSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(domSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }  }
DOMSourceEntityProvider implements EntityProvider<DOMSource> { @Override public void writeTo(DOMSource domSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(domSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override DOMSource readFrom(Class<DOMSource> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream); @Override long getSize(DOMSource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(DOMSource domSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream); }
DOMSourceEntityProvider implements EntityProvider<DOMSource> { @Override public void writeTo(DOMSource domSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { StreamResult streamResult = new StreamResult(entityStream); try { TransformerFactory factory = createFeaturedTransformerFactory(); factory.newTransformer().transform(domSource, streamResult); } catch (TransformerException | TransformerFactoryConfigurationError e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override DOMSource readFrom(Class<DOMSource> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream); @Override long getSize(DOMSource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(DOMSource domSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }