|
36 | 36 | import com.google.firebase.crashlytics.internal.send.DataTransportCrashlyticsReportSender; |
37 | 37 | import com.google.firebase.crashlytics.internal.settings.SettingsProvider; |
38 | 38 | import com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy; |
| 39 | +import java.io.BufferedInputStream; |
39 | 40 | import java.io.ByteArrayOutputStream; |
40 | 41 | import java.io.File; |
41 | 42 | import java.io.IOException; |
@@ -427,13 +428,15 @@ private static CrashlyticsReport.ApplicationExitInfo convertApplicationExitInfo( |
427 | 428 | @VisibleForTesting |
428 | 429 | @RequiresApi(api = Build.VERSION_CODES.KITKAT) |
429 | 430 | public static String convertInputStreamToString(InputStream inputStream) throws IOException { |
430 | | - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
431 | | - byte[] bytes = new byte[DEFAULT_BUFFER_SIZE]; |
432 | | - int length; |
433 | | - while ((length = inputStream.read(bytes)) != -1) { |
434 | | - byteArrayOutputStream.write(bytes, 0, length); |
| 431 | + try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); |
| 432 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { |
| 433 | + byte[] bytes = new byte[DEFAULT_BUFFER_SIZE]; |
| 434 | + int length; |
| 435 | + while ((length = bufferedInputStream.read(bytes)) != -1) { |
| 436 | + byteArrayOutputStream.write(bytes, 0, length); |
| 437 | + } |
| 438 | + return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()); |
435 | 439 | } |
436 | | - return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()); |
437 | 440 | } |
438 | 441 |
|
439 | 442 | /** Finds the first ANR ApplicationExitInfo within the session. */ |
|
0 commit comments