Skip to content

Commit 87774e6

Browse files
committed
Modify response body parse
1 parent ac6fa8d commit 87774e6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/io/split/android/client/network/HttpRequestImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import androidx.annotation.NonNull;
1111
import androidx.annotation.Nullable;
1212

13-
import java.io.BufferedReader;
13+
import java.io.ByteArrayOutputStream;
1414
import java.io.IOException;
1515
import java.io.InputStream;
16-
import java.io.InputStreamReader;
1716
import java.io.OutputStream;
1817
import java.net.HttpRetryException;
1918
import java.net.HttpURLConnection;
@@ -234,19 +233,22 @@ private static HttpResponse buildResponse(HttpURLConnection connection) throws I
234233
int responseCode = connection.getResponseCode();
235234

236235
if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < 300) {
237-
StringBuilder responseData = new StringBuilder();
236+
String responseData = null;
238237
try (InputStream inputStream = connection.getInputStream()) {
239238
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");
245247
}
246248
}
247249
}
248250

249-
return new HttpResponseImpl(responseCode, (responseData.length() > 0 ? responseData.toString() : null));
251+
return new HttpResponseImpl(responseCode, responseData);
250252
}
251253

252254
return new HttpResponseImpl(responseCode);

0 commit comments

Comments
 (0)