Skip to content

Commit 30d7a0f

Browse files
committed
Handy method to specify charset in anonymous inner instances
1 parent 5a7a835 commit 30d7a0f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

library/src/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public void setCharset(final String charset) {
8686
this.responseCharset = charset;
8787
}
8888

89+
public String getCharset() {
90+
return this.responseCharset;
91+
}
92+
8993
/**
9094
* Creates a new AsyncHttpResponseHandler
9195
*/
@@ -172,8 +176,8 @@ public void onFailure(Throwable error, String content) {
172176
* Fired when a request fails to complete, override to handle in your own code
173177
*
174178
* @param statusCode return HTTP status code
175-
* @param error the underlying cause of the failure
176-
* @param content the response body, if any
179+
* @param error the underlying cause of the failure
180+
* @param content the response body, if any
177181
*/
178182
public void onFailure(int statusCode, Throwable error, String content) {
179183
// By default, call the chain method onFailure(Throwable,String)
@@ -184,9 +188,9 @@ public void onFailure(int statusCode, Throwable error, String content) {
184188
* Fired when a request fails to complete, override to handle in your own code
185189
*
186190
* @param statusCode return HTTP status code
187-
* @param headers return headers, if any
188-
* @param error the underlying cause of the failure
189-
* @param content the response body, if any
191+
* @param headers return headers, if any
192+
* @param error the underlying cause of the failure
193+
* @param content the response body, if any
190194
*/
191195
public void onFailure(int statusCode, Header[] headers, Throwable error, String content) {
192196
// By default, call the chain method onFailure(int,Throwable,String)
@@ -216,7 +220,7 @@ protected void sendFailureMessage(int statusCode, Header[] headers, Throwable e,
216220
}
217221

218222
@Deprecated
219-
protected void sendFailureMessage( Throwable e, byte[] responseBody) {
223+
protected void sendFailureMessage(Throwable e, byte[] responseBody) {
220224
sendMessage(obtainMessage(FAILURE_MESSAGE, new Object[]{0, null, e, responseBody}));
221225
}
222226

@@ -295,7 +299,7 @@ protected void sendResponseMessage(HttpResponse response) {
295299
HttpEntity temp = response.getEntity();
296300
if (temp != null) {
297301
entity = new BufferedHttpEntity(temp);
298-
responseBody = EntityUtils.toString(entity, responseCharset);
302+
responseBody = EntityUtils.toString(entity, getCharset());
299303
}
300304
} catch (IOException e) {
301305
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), e, (String) null);

0 commit comments

Comments
 (0)