class 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();
        }
    }

}