### Question:
DataSourceProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { DataSource ds = DataSource.class.isAssignableFrom(cls) ? (DataSource)src : ((DataHandler)src).getDataSource(); if (useDataSourceContentType) { setContentTypeIfNeeded(type, headers, ds.getContentType()); } IOUtils.copyAndCloseInput(ds.getInputStream(), os); }  boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); T readFrom(Class<T> cls, Type genericType, Annotation[] annotations,
                               MediaType type,
                               MultivaluedMap<String, String> headers, InputStream is); long getSize(T t, Class<?> type, Type genericType, Annotation[] annotations,
                        MediaType mt); boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt); void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
                        MediaType type, MultivaluedMap<String, Object> headers, OutputStream os); void setUseDataSourceContentType(boolean useDataSourceContentType);  }### Answer:
@Test public void testWriteDataHandler() throws Exception { DataSourceProvider<DataHandler> p = new DataSourceProvider<>(); DataHandler ds = new DataHandler(new InputStreamDataSource( new ByteArrayInputStream("image".getBytes()), "image/png")); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.writeTo(ds, DataHandler.class, DataHandler.class, new Annotation[]{}, MediaType.valueOf("image/png"), new MetadataMap<String, Object>(), os); assertEquals("image", os.toString()); }
@Test public void testWriteDataSource() throws Exception { DataSourceProvider<DataSource> p = new DataSourceProvider<>(); DataSource ds = new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()), "image/png"); MultivaluedMap<String, Object> outHeaders = new MetadataMap<>(); try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { p.writeTo(ds, DataSource.class, DataSource.class, new Annotation[]{}, MediaType.valueOf("image/png"), outHeaders, os); assertEquals("image", os.toString()); } assertEquals(0, outHeaders.size()); }