### Question:
DataSourceProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { public T readFrom(Class<T> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, String> headers, InputStream is) throws IOException { DataSource ds = null; if (cls == FileDataSource.class) { File file = new BinaryDataProvider<File>().readFrom(File.class, File.class, annotations, type, headers, is); ds = new FileDataSource(file); } else if (cls == DataSource.class || cls == DataHandler.class) { ds = new InputStreamDataSource(is, type.toString()); } else { LOG.warning("Unsupported DataSource class: " + cls.getName()); throw ExceptionUtils.toWebApplicationException(null, null); } return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds)); }  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 testReadDataHandler() throws Exception { DataSourceProvider<DataHandler> p = new DataSourceProvider<>(); DataHandler ds = p.readFrom(DataHandler.class, null, new Annotation[]{}, MediaType.valueOf("image/png"), new MetadataMap<String, String>(), new ByteArrayInputStream("image".getBytes())); assertEquals("image", IOUtils.readStringFromStream(ds.getDataSource().getInputStream())); }
@Test public void testReadDataSource() throws Exception { DataSourceProvider<DataSource> p = new DataSourceProvider<>(); DataSource ds = p.readFrom(DataSource.class, null, new Annotation[]{}, MediaType.valueOf("image/png"), new MetadataMap<String, String>(), new ByteArrayInputStream("image".getBytes())); assertEquals("image", IOUtils.readStringFromStream(ds.getInputStream())); }