@Test public void writesFileToOutputStream() throws Exception { ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(testContent, TEXT_PLAIN); ByteArrayOutputStream out = new ByteArrayOutputStream(); MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); dataSourceEntityProvider.writeTo(byteArrayDataSource, DataSource.class, null, null, null, headers, out); assertArrayEquals(testContent, out.toByteArray()); assertEquals(TEXT_PLAIN, headers.getFirst(CONTENT_TYPE)); }
@Override public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (httpHeaders.getFirst(CONTENT_TYPE) == null && !isNullOrEmpty(dataSource.getContentType())) { httpHeaders.putSingle(CONTENT_TYPE, dataSource.getContentType()); } try (InputStream in = dataSource.getInputStream()) { ByteStreams.copy(in, entityStream); } }
DataSourceEntityProvider implements EntityProvider<DataSource> { @Override public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (httpHeaders.getFirst(CONTENT_TYPE) == null && !isNullOrEmpty(dataSource.getContentType())) { httpHeaders.putSingle(CONTENT_TYPE, dataSource.getContentType()); } try (InputStream in = dataSource.getInputStream()) { ByteStreams.copy(in, entityStream); } } }
DataSourceEntityProvider implements EntityProvider<DataSource> { @Override public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (httpHeaders.getFirst(CONTENT_TYPE) == null && !isNullOrEmpty(dataSource.getContentType())) { httpHeaders.putSingle(CONTENT_TYPE, dataSource.getContentType()); } try (InputStream in = dataSource.getInputStream()) { ByteStreams.copy(in, entityStream); } }  }
DataSourceEntityProvider implements EntityProvider<DataSource> { @Override public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (httpHeaders.getFirst(CONTENT_TYPE) == null && !isNullOrEmpty(dataSource.getContentType())) { httpHeaders.putSingle(CONTENT_TYPE, dataSource.getContentType()); } try (InputStream in = dataSource.getInputStream()) { ByteStreams.copy(in, entityStream); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override DataSource readFrom(Class<DataSource> type,
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType,
                               MultivaluedMap<String, String> httpHeaders,
                               InputStream entityStream); @Override long getSize(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(DataSource dataSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream); }
DataSourceEntityProvider implements EntityProvider<DataSource> { @Override public void writeTo(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (httpHeaders.getFirst(CONTENT_TYPE) == null && !isNullOrEmpty(dataSource.getContentType())) { httpHeaders.putSingle(CONTENT_TYPE, dataSource.getContentType()); } try (InputStream in = dataSource.getInputStream()) { ByteStreams.copy(in, entityStream); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override DataSource readFrom(Class<DataSource> type,
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType,
                               MultivaluedMap<String, String> httpHeaders,
                               InputStream entityStream); @Override long getSize(DataSource dataSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(DataSource dataSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }