From d9f67661d36644e288d7b8839fa2f8bb208822d1 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 25 May 2021 13:38:54 -0400 Subject: [PATCH] Handle IOException in readUnexpectedStderr --- .../java/be/mygod/librootkotlinx/RootServer.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index fcb3dac4..9eb108d6 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -107,12 +107,16 @@ class RootServer { if (!this::process.isInitialized) return null var available = process.errorStream.available() return if (available <= 0) null else String(ByteArrayOutputStream().apply { - while (available > 0) { - val bytes = ByteArray(available) - val len = process.errorStream.read(bytes) - if (len < 0) throw EOFException() // should not happen - write(bytes, 0, len) - available = process.errorStream.available() + try { + while (available > 0) { + val bytes = ByteArray(available) + val len = process.errorStream.read(bytes) + if (len < 0) throw EOFException() // should not happen + write(bytes, 0, len) + available = process.errorStream.available() + } + } catch (e: IOException) { + Logger.me.w("Reading stderr was cut short", e) } }.toByteArray()) }