Skip to content

Commit

Permalink
Ignoring stream closed error on session end
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Feb 21, 2017
1 parent 07f67cd commit a10dead
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/kotlin/com/waicool20/kaga/util/StreamGobbler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import java.io.InputStreamReader

class StreamGobbler(val process: Process?) {
fun run() {
val readOut = Thread { BufferedReader(InputStreamReader(process?.inputStream)).forEachLine(::println) }
val readErr = Thread { BufferedReader(InputStreamReader(process?.errorStream)).forEachLine(::println) }
readOut.start()
readErr.start()
val handler = Thread.UncaughtExceptionHandler { thread, throwable ->
if (throwable.message != "Stream closed") throw throwable // Ignore stream closed errors
}
with(Thread { BufferedReader(InputStreamReader(process?.inputStream)).forEachLine(::println) }) {
uncaughtExceptionHandler = handler
start()
}
with(Thread { BufferedReader(InputStreamReader(process?.errorStream)).forEachLine(::println) }) {
uncaughtExceptionHandler = handler
start()
}
}
}

0 comments on commit a10dead

Please sign in to comment.