|
10 | 10 | import androidx.annotation.NonNull; |
11 | 11 | import androidx.annotation.Nullable; |
12 | 12 |
|
13 | | -import java.io.BufferedReader; |
| 13 | +import java.io.ByteArrayOutputStream; |
14 | 14 | import java.io.IOException; |
15 | 15 | import java.io.InputStream; |
16 | | -import java.io.InputStreamReader; |
17 | 16 | import java.io.OutputStream; |
18 | 17 | import java.net.HttpRetryException; |
19 | 18 | import java.net.HttpURLConnection; |
@@ -234,19 +233,22 @@ private static HttpResponse buildResponse(HttpURLConnection connection) throws I |
234 | 233 | int responseCode = connection.getResponseCode(); |
235 | 234 |
|
236 | 235 | if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < 300) { |
237 | | - StringBuilder responseData = new StringBuilder(); |
| 236 | + String responseData = null; |
238 | 237 | try (InputStream inputStream = connection.getInputStream()) { |
239 | 238 | if (inputStream != null) { |
240 | | - try (BufferedReader in = new BufferedReader(new InputStreamReader(inputStream))) { |
241 | | - String inputLine; |
242 | | - while ((inputLine = in.readLine()) != null) { |
243 | | - responseData.append(inputLine); |
244 | | - } |
| 239 | + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
| 240 | + byte[] data = new byte[8192]; |
| 241 | + int bytesRead; |
| 242 | + while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) { |
| 243 | + buffer.write(data, 0, bytesRead); |
| 244 | + } |
| 245 | + if (buffer.size() > 0) { |
| 246 | + responseData = buffer.toString("UTF-8"); |
245 | 247 | } |
246 | 248 | } |
247 | 249 | } |
248 | 250 |
|
249 | | - return new HttpResponseImpl(responseCode, (responseData.length() > 0 ? responseData.toString() : null)); |
| 251 | + return new HttpResponseImpl(responseCode, responseData); |
250 | 252 | } |
251 | 253 |
|
252 | 254 | return new HttpResponseImpl(responseCode); |
|
0 commit comments