class 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);
    }

}