FileEntityProvider implements EntityProvider<File> { @Override public File readFrom(Class<File> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { File f = FileCollector.getInstance().createFile(); try (OutputStream out = new FileOutputStream(f)) { ByteStreams.copy(entityStream, out); } return f; }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override File readFrom(Class<File> type,
                         Type genericType,
                         Annotation[] annotations,
                         MediaType mediaType,
                         MultivaluedMap<String, String> httpHeaders,
                         InputStream entityStream); @Override long getSize(File file, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(File file,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream);  }
@Test public void readsContentOfEntityStreamAsFile() throws Exception { File result = fileEntityProvider.readFrom(File.class, null, null, null, null, new ByteArrayInputStream(testContent)); assertTrue(result.exists()); byte[] bytes = Files.toByteArray(result); assertArrayEquals(testContent, bytes); }