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