Skip to content

Commit

Permalink
Handy method to specify charset in anonymous inner instances
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Oct 13, 2013
1 parent 5a7a835 commit 30d7a0f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions library/src/com/loopj/android/http/AsyncHttpResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void setCharset(final String charset) {
this.responseCharset = charset;
}

public String getCharset() {
return this.responseCharset;
}

/**
* Creates a new AsyncHttpResponseHandler
*/
Expand Down Expand Up @@ -172,8 +176,8 @@ public void onFailure(Throwable error, String content) {
* Fired when a request fails to complete, override to handle in your own code
*
* @param statusCode return HTTP status code
* @param error the underlying cause of the failure
* @param content the response body, if any
* @param error the underlying cause of the failure
* @param content the response body, if any
*/
public void onFailure(int statusCode, Throwable error, String content) {
// By default, call the chain method onFailure(Throwable,String)
Expand All @@ -184,9 +188,9 @@ public void onFailure(int statusCode, Throwable error, String content) {
* Fired when a request fails to complete, override to handle in your own code
*
* @param statusCode return HTTP status code
* @param headers return headers, if any
* @param error the underlying cause of the failure
* @param content the response body, if any
* @param headers return headers, if any
* @param error the underlying cause of the failure
* @param content the response body, if any
*/
public void onFailure(int statusCode, Header[] headers, Throwable error, String content) {
// By default, call the chain method onFailure(int,Throwable,String)
Expand Down Expand Up @@ -216,7 +220,7 @@ protected void sendFailureMessage(int statusCode, Header[] headers, Throwable e,
}

@Deprecated
protected void sendFailureMessage( Throwable e, byte[] responseBody) {
protected void sendFailureMessage(Throwable e, byte[] responseBody) {
sendMessage(obtainMessage(FAILURE_MESSAGE, new Object[]{0, null, e, responseBody}));
}

Expand Down Expand Up @@ -295,7 +299,7 @@ protected void sendResponseMessage(HttpResponse response) {
HttpEntity temp = response.getEntity();
if (temp != null) {
entity = new BufferedHttpEntity(temp);
responseBody = EntityUtils.toString(entity, responseCharset);
responseBody = EntityUtils.toString(entity, getCharset());
}
} catch (IOException e) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), e, (String) null);
Expand Down

0 comments on commit 30d7a0f

Please sign in to comment.