StreamSourceEntityProvider implements EntityProvider<StreamSource> { @Override public StreamSource readFrom(Class<StreamSource> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return new StreamSource(entityStream); }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override StreamSource readFrom(Class<StreamSource> type,
                                 Type genericType,
                                 Annotation[] annotations,
                                 MediaType mediaType,
                                 MultivaluedMap<String, String> httpHeaders,
                                 InputStream entityStream); @Override long getSize(StreamSource streamSource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(StreamSource streamSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }
@Test public void readsContentOfEntityStreamAsStreamSource() throws Exception { StreamSource streamSource = streamSourceEntityProvider.readFrom(StreamSource.class, null, null, APPLICATION_XML_TYPE, new MultivaluedMapImpl(), new ByteArrayInputStream(TEST_XML_CONTENT_BYTES)); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(streamSource.getInputStream()); assertThatXmlDocumentContainsAllExpectedNodes(document); }