Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/src/main/java/feign/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public interface Body extends 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 {
Expand Down Expand Up @@ -260,6 +265,12 @@ public Reader asReader() throws IOException {
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();
Expand Down Expand Up @@ -309,6 +320,12 @@ public Reader asReader() throws IOException {
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 {}

Expand Down
6 changes: 6 additions & 0 deletions core/src/test/java/feign/FeignBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -399,6 +400,11 @@ public Reader asReader() throws IOException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand All @@ -52,7 +53,7 @@
/**
* This module directs Feign's http requests to Apache's
* <a href="https://hc.apache.org/httpcomponents-client-ga/">HttpClient</a>. Ex.
*
*
* <pre>
* GitHub github = Feign.builder().client(new ApacheHttpClient()).target(GitHub.class,
* "https://api.github.com");
Expand Down Expand Up @@ -224,6 +225,12 @@ public Reader asReader() throws IOException {
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);
Expand Down
6 changes: 6 additions & 0 deletions okhttp/src/main/java/feign/okhttp/OkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -142,6 +143,11 @@ public InputStream asInputStream() throws IOException {
public Reader asReader() throws IOException {
return input.charStream();
}

@Override
public Reader asReader(Charset charset) throws IOException {
return asReader();
}
};
}

Expand Down