ReaderEntityProvider implements EntityProvider<Reader> { @Override public void writeTo(Reader reader, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { Writer out = new OutputStreamWriter(entityStream, getCharsetOrUtf8(mediaType)); try { CharStreams.copy(reader, out); } finally { out.flush(); reader.close(); } }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override Reader readFrom(Class<Reader> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders, InputStream entityStream); @Override long getSize(Reader t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Reader reader, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream);  }
@Test public void writesReaderToOutputStream() throws Exception { MediaType mediaType = new MediaType("text", "plain", ImmutableMap.of("charset", "windows-1251")); ByteArrayOutputStream out = new ByteArrayOutputStream(); readerEntityProvider.writeTo(new StringReader(TEST_CONTENT), String.class, null, null, mediaType, new MultivaluedHashMap<>(), out); assertArrayEquals(TEST_CONTENT.getBytes("windows-1251"), out.toByteArray()); }
@Test public void writesUtf8ReaderToOutputStream() throws Exception { MediaType mediaType = new MediaType("text", "plain"); ByteArrayOutputStream out = new ByteArrayOutputStream(); readerEntityProvider.writeTo(new StringReader(TEST_CONTENT), String.class, null, null, mediaType, new MultivaluedHashMap<>(), out); assertArrayEquals(TEST_CONTENT.getBytes("UTF-8"), out.toByteArray()); }