5
5
import java .io .UnsupportedEncodingException ;
6
6
7
7
/**
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
10
10
* designed to be anonymously overridden with your own response handling code.
11
- * <p>
11
+ * <p/ >
12
12
* Additionally, you can override the {@link #onFailure(String, Throwable)},
13
13
* {@link #onStart()}, and {@link #onFinish()} methods as required.
14
- * <p>
14
+ * <p/ >
15
15
* For example:
16
- * <p>
16
+ * <p/ >
17
17
* <pre>
18
18
* AsyncHttpClient client = new AsyncHttpClient();
19
19
* client.get("http://www.google.com", new TextHttpResponseHandler() {
26
26
* public void onSuccess(String responseBody) {
27
27
* // Successfully got a response
28
28
* }
29
- *
29
+ *
30
30
* @Override
31
31
* public void onFailure(String responseBody, Throwable e) {
32
32
* // Response failed :(
42
42
public class TextHttpResponseHandler extends AsyncHttpResponseHandler {
43
43
44
44
private String _encoding ;
45
+
45
46
/**
46
47
* Creates a new TextHttpResponseHandler
47
48
*/
48
-
49
- public TextHttpResponseHandler ()
50
- {
51
- this ("UTF-8" );
49
+
50
+ public TextHttpResponseHandler () {
51
+ this (DEFAULT_CHARSET );
52
52
}
53
-
53
+
54
54
public TextHttpResponseHandler (String encoding ) {
55
55
super ();
56
56
_encoding = encoding ;
@@ -62,45 +62,45 @@ public TextHttpResponseHandler(String encoding) {
62
62
/**
63
63
* Fired when a request returns successfully, override to handle in your own
64
64
* code
65
- *
65
+ *
66
66
* @param responseBody the body of the HTTP response from the server
67
67
*/
68
68
public void onSuccess (String responseBody ) {
69
69
}
70
-
70
+
71
71
/**
72
72
* Fired when a request returns successfully, override to handle in your own
73
73
* 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
77
77
* @param responseBody the body of the HTTP response from the server
78
78
*/
79
79
public void onSuccess (int statusCode , Header [] headers , String responseBody ) {
80
- onSuccess ( responseBody );
80
+ onSuccess (responseBody );
81
81
}
82
82
83
83
/**
84
84
* Fired when a request fails to complete, override to handle in your own
85
85
* code
86
- *
86
+ *
87
87
* @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
+ */
90
90
public void onFailure (String responseBody , Throwable error ) {
91
91
}
92
-
92
+
93
93
/**
94
94
* Fired when a request fails to complete, override to handle in your own
95
95
* 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
99
99
* @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
+ */
102
102
public void onFailure (int statusCode , Header [] headers , String responseBody , Throwable error ) {
103
- onFailure ( responseBody , error );
103
+ onFailure (responseBody , error );
104
104
}
105
105
106
106
@ Override
@@ -120,5 +120,5 @@ public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Thr
120
120
onFailure (0 , headers , (String ) null , e );
121
121
}
122
122
}
123
-
123
+
124
124
}
0 commit comments