### Question:
SourceProvider extends AbstractConfigurableProvider implements
    MessageBodyReader<T>, MessageBodyWriter<T> { public void writeTo(T source, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name()); XMLStreamReader reader = null; if (source instanceof Source) { reader = StaxUtils.createXMLStreamReader((Source)source); } else if (source instanceof Document) { reader = StaxUtils.createXMLStreamReader((Document)source); } else { reader = StaxUtils.createXMLStreamReader(new DOMSource((Node)source)); } XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, encoding); try { StaxUtils.copy(reader, writer); } catch (XMLStreamException e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } finally { try { reader.close(); } catch (XMLStreamException e) { } try { writer.flush(); writer.close(); } catch (XMLStreamException e) { } } }  boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); T readFrom(Class<T> source, Type genericType, Annotation[] annotations, MediaType m,
        MultivaluedMap<String, String> headers, InputStream is); void writeTo(T source, Class<?> clazz, Type genericType, Annotation[] annotations,
        MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os); long getSize(T source, Class<?> type, Type genericType, Annotation[] annotations,
                        MediaType mt);  }### Answer:
@Test public void testWriteToDocument() throws Exception { SourceProvider<Document> p = new SourceProvider<>(); Document doc = StaxUtils.read(new StringReader("<test/>")); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.writeTo(doc, Document.class, Document.class, new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os); String s = os.toString(); assertEquals("<test/>", s); }
@Test public void testWriteTo() throws Exception { SourceProvider<Source> p = new TestSourceProvider<>(); StreamSource s = new StreamSource(new ByteArrayInputStream("<test/>".getBytes())); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.writeTo(s, null, null, null, MediaType.APPLICATION_XML_TYPE, new MetadataMap<String, Object>(), os); assertTrue(os.toString().contains("<test/>")); os = new ByteArrayOutputStream(); p.writeTo(createDomSource(), null, null, null, MediaType.APPLICATION_XML_TYPE, new MetadataMap<String, Object>(), os); assertTrue(os.toString().contains("<test/>")); }