Search in sources :

Example 6 with InputStreamDataSource

use of org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource in project cxf by apache.

the class DataSourceProvider method readFrom.

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));
}
Also used : InputStreamDataSource(org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) File(java.io.File) InputStreamDataSource(org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Aggregations

InputStreamDataSource (org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.Test)5 DataHandler (javax.activation.DataHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataSource (javax.activation.DataSource)3 InputStream (java.io.InputStream)2 PushbackInputStream (java.io.PushbackInputStream)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)2 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 File (java.io.File)1 FileDataSource (javax.activation.FileDataSource)1