DataSourceEntityProvider implements EntityProvider<DataSource> { @Override public DataSource readFrom(Class<DataSource> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return createDataSource(entityStream, mediaType == null ? null : mediaType.toString()); }  @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);  }
@Test public void readsContentOfEntityStreamAsDataSource() throws Exception { DataSource result = dataSourceEntityProvider.readFrom(DataSource.class, null, null, TEXT_PLAIN_TYPE, null, new ByteArrayInputStream(testContent)); assertTrue(result instanceof ByteArrayDataSource); byte[] bytes = ByteStreams.toByteArray(result.getInputStream()); assertArrayEquals(testContent, bytes); assertEquals(TEXT_PLAIN, result.getContentType()); }
@Test public void buffersContentOfEntityStreamToFileAndReadsAsDataSource() throws Exception { when(context.getEverrestConfiguration().getMaxBufferSize()).thenReturn(8); DataSource result = dataSourceEntityProvider.readFrom(DataSource.class, null, null, TEXT_PLAIN_TYPE, null, new ByteArrayInputStream(testContent)); assertTrue(result instanceof FileDataSource); byte[] bytes = ByteStreams.toByteArray(result.getInputStream()); assertArrayEquals(testContent, bytes); assertEquals(TEXT_PLAIN, result.getContentType()); }