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)); }
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)); }
BinaryDataProvider<Object> p = new BinaryDataProvider<>(); p.setProduceMediaTypes(Collections.singletonList("application/bar")); p.setEnableBuffering(true);
protected static void initFactory(ProviderFactory factory) { // ensure to not load providers not available in a module environment if not needed factory.setProviders(false, false, new BinaryDataProvider<Object>(), new SourceProvider<Object>(), tryCreateInstance("org.apache.cxf.jaxrs.provider.DataSourceProvider"), new FormEncodingProvider<Object>(), new StringTextProvider(), new PrimitiveTextProvider<Object>(), tryCreateInstance(JAXB_PROVIDER_NAME), tryCreateInstance("org.apache.cxf.jaxrs.provider.JAXBElementTypedProvider"), tryCreateInstance("org.apache.cxf.jaxrs.provider.MultipartProvider")); Object prop = factory.getBus().getProperty("skip.default.json.provider.registration"); if (!PropertyUtils.isTrue(prop)) { factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME, factory.getBus())); } }