diff --git a/core/src/main/java/feign/Response.java b/core/src/main/java/feign/Response.java index 366f2751..46499067 100644 --- a/core/src/main/java/feign/Response.java +++ b/core/src/main/java/feign/Response.java @@ -221,6 +221,11 @@ public final class Response implements Closeable { * It is the responsibility of the caller to close the stream. */ Reader asReader() throws IOException; + + /** + * + */ + Reader asReader(Charset charset) throws IOException; } private static final class InputStreamBody implements Response.Body { @@ -260,6 +265,12 @@ public final class Response implements Closeable { return new InputStreamReader(inputStream, UTF_8); } + @Override + public Reader asReader(Charset charset) throws IOException { + checkNotNull(charset, "charset should not be null"); + return new InputStreamReader(inputStream, charset); + } + @Override public void close() throws IOException { inputStream.close(); @@ -309,6 +320,12 @@ public final class Response implements Closeable { return new InputStreamReader(asInputStream(), UTF_8); } + @Override + public Reader asReader(Charset charset) throws IOException { + checkNotNull(charset, "charset should not be null"); + return new InputStreamReader(asInputStream(), charset); + } + @Override public void close() throws IOException {} diff --git a/core/src/test/java/feign/FeignBuilderTest.java b/core/src/test/java/feign/FeignBuilderTest.java index a69b4c68..74694b93 100644 --- a/core/src/test/java/feign/FeignBuilderTest.java +++ b/core/src/test/java/feign/FeignBuilderTest.java @@ -21,6 +21,7 @@ import org.junit.Test; import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.nio.charset.Charset; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Type; @@ -399,6 +400,11 @@ public class FeignBuilderTest { return original.body().asReader(); } + @Override + public Reader asReader(Charset charset) throws IOException { + return original.body().asReader(charset); + } + @Override public void close() throws IOException { closed.set(true); diff --git a/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java b/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java index 0a16ac61..7919506a 100644 --- a/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java +++ b/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.Charset; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URI; @@ -52,7 +53,7 @@ import static feign.Util.UTF_8; /** * This module directs Feign's http requests to Apache's * HttpClient. Ex. - * + * *
  * GitHub github = Feign.builder().client(new ApacheHttpClient()).target(GitHub.class,
  * "https://api.github.com");
@@ -224,6 +225,12 @@ public final class ApacheHttpClient implements Client {
         return new InputStreamReader(asInputStream(), UTF_8);
       }
 
+      @Override
+      public Reader asReader(Charset charset) throws IOException {
+        Util.checkNotNull(charset, "charset should not be null");
+        return new InputStreamReader(asInputStream(), charset);
+      }
+
       @Override
       public void close() throws IOException {
         EntityUtils.consume(entity);
diff --git a/okhttp/src/main/java/feign/okhttp/OkHttpClient.java b/okhttp/src/main/java/feign/okhttp/OkHttpClient.java
index 94064c70..bbe4670e 100644
--- a/okhttp/src/main/java/feign/okhttp/OkHttpClient.java
+++ b/okhttp/src/main/java/feign/okhttp/OkHttpClient.java
@@ -22,6 +22,7 @@ import okhttp3.ResponseBody;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
+import java.nio.charset.Charset;
 import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -142,6 +143,11 @@ public final class OkHttpClient implements Client {
       public Reader asReader() throws IOException {
         return input.charStream();
       }
+
+      @Override
+      public Reader asReader(Charset charset) throws IOException {
+        return asReader();
+      }
     };
   }