Skip to content

Commit

Permalink
Merge branch 'artem-zinnatullin-response-body-string-javadoc'
Browse files Browse the repository at this point in the history
* artem-zinnatullin-response-body-string-javadoc:
  Clarify behavior of ResponseBody.string() in its javadoc
  • Loading branch information
squarejesse committed Jul 30, 2016
2 parents 915c3a4 + eb20b15 commit 6dd8da7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion okhttp/src/main/java/okhttp3/ResponseBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public final InputStream byteStream() {

public abstract BufferedSource source();

/**
* Returns the response as a byte array.
*
* <p>This method loads entire response body into memory. If the response body is very large this
* may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a
* possibility for your response.
*/
public final byte[] bytes() throws IOException {
long contentLength = contentLength();
if (contentLength > Integer.MAX_VALUE) {
Expand Down Expand Up @@ -148,7 +155,11 @@ public final Reader charStream() {
/**
* Returns the response as a string decoded with the charset of the Content-Type header. If that
* header is either absent or lacks a charset, this will attempt to decode the response body as
* UTF-8.
* UTF-8. Closes {@link ResponseBody} automatically.
*
* <p>This method loads entire response body into memory. If the response body is very large this
* may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a
* possibility for your response.
*/
public final String string() throws IOException {
return new String(bytes(), charset().name());
Expand Down

0 comments on commit 6dd8da7

Please sign in to comment.