Skip to content

Commit aa00c99

Browse files
committed
Default charset
1 parent b634d4c commit aa00c99

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public class AsyncHttpResponseHandler {
9393
protected static final int BUFFER_SIZE = 4096;
9494

9595
private Handler handler;
96-
private String responseCharset = "UTF-8";
96+
public static final String DEFAULT_CHARSET = "UTF-8";
97+
private String responseCharset = DEFAULT_CHARSET;
9798
private Boolean useSynchronousMode = false;
9899

99100
// avoid leaks by using a non-anonymous handler class

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import java.io.UnsupportedEncodingException;
66

77
/**
8-
* Used to intercept and handle the responses from requests made using
9-
* {@link AsyncHttpClient}. The {@link #onSuccess(String)} method is
8+
* Used to intercept and handle the responses from requests made using
9+
* {@link AsyncHttpClient}. The {@link #onSuccess(String)} method is
1010
* designed to be anonymously overridden with your own response handling code.
11-
* <p>
11+
* <p/>
1212
* Additionally, you can override the {@link #onFailure(String, Throwable)},
1313
* {@link #onStart()}, and {@link #onFinish()} methods as required.
14-
* <p>
14+
* <p/>
1515
* For example:
16-
* <p>
16+
* <p/>
1717
* <pre>
1818
* AsyncHttpClient client = new AsyncHttpClient();
1919
* client.get("http://www.google.com", new TextHttpResponseHandler() {
@@ -26,7 +26,7 @@
2626
* public void onSuccess(String responseBody) {
2727
* // Successfully got a response
2828
* }
29-
*
29+
*
3030
* &#064;Override
3131
* public void onFailure(String responseBody, Throwable e) {
3232
* // Response failed :(
@@ -42,15 +42,15 @@
4242
public class TextHttpResponseHandler extends AsyncHttpResponseHandler {
4343

4444
private String _encoding;
45+
4546
/**
4647
* Creates a new TextHttpResponseHandler
4748
*/
48-
49-
public TextHttpResponseHandler()
50-
{
51-
this("UTF-8");
49+
50+
public TextHttpResponseHandler() {
51+
this(DEFAULT_CHARSET);
5252
}
53-
53+
5454
public TextHttpResponseHandler(String encoding) {
5555
super();
5656
_encoding = encoding;
@@ -62,45 +62,45 @@ public TextHttpResponseHandler(String encoding) {
6262
/**
6363
* Fired when a request returns successfully, override to handle in your own
6464
* code
65-
*
65+
*
6666
* @param responseBody the body of the HTTP response from the server
6767
*/
6868
public void onSuccess(String responseBody) {
6969
}
70-
70+
7171
/**
7272
* Fired when a request returns successfully, override to handle in your own
7373
* code
74-
*
75-
* @param statusCode the status code of the response
76-
* @param headers HTTP response headers
74+
*
75+
* @param statusCode the status code of the response
76+
* @param headers HTTP response headers
7777
* @param responseBody the body of the HTTP response from the server
7878
*/
7979
public void onSuccess(int statusCode, Header[] headers, String responseBody) {
80-
onSuccess( responseBody );
80+
onSuccess(responseBody);
8181
}
8282

8383
/**
8484
* Fired when a request fails to complete, override to handle in your own
8585
* code
86-
*
86+
*
8787
* @param responseBody the response body, if any
88-
* @param error the underlying cause of the failure
89-
*/
88+
* @param error the underlying cause of the failure
89+
*/
9090
public void onFailure(String responseBody, Throwable error) {
9191
}
92-
92+
9393
/**
9494
* Fired when a request fails to complete, override to handle in your own
9595
* code
96-
*
97-
* @param statusCode the status code of the response
98-
* @param headers HTTP response headers
96+
*
97+
* @param statusCode the status code of the response
98+
* @param headers HTTP response headers
9999
* @param responseBody the response body, if any
100-
* @param error the underlying cause of the failure
101-
*/
100+
* @param error the underlying cause of the failure
101+
*/
102102
public void onFailure(int statusCode, Header[] headers, String responseBody, Throwable error) {
103-
onFailure( responseBody, error );
103+
onFailure(responseBody, error);
104104
}
105105

106106
@Override
@@ -120,5 +120,5 @@ public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Thr
120120
onFailure(0, headers, (String) null, e);
121121
}
122122
}
123-
123+
124124
}

0 commit comments

Comments
 (0)