Skip to content

Commit

Permalink
use when
Browse files Browse the repository at this point in the history
  • Loading branch information
edgao committed Sep 9, 2024
1 parent 7a965e4 commit e476fcc
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,21 @@ private class LazyInputStreamReader(private val input: InputStream) {
return NoLine.EOF
}
while (input.available() != 0) {
val read = input.read()
if (read == -1) {
eof = true
val line = Line(buffer.toByteArray().toString(Charsets.UTF_8))
buffer.reset()
return line
} else {
if (read == '\n'.code) {
val bytes = buffer.toByteArray()
buffer.reset()
return Line(bytes.toString(Charsets.UTF_8))
} else {
buffer.write(read)
}
when (val read = input.read()) {
-1 -> {
eof = true
val line = Line(buffer.toByteArray().toString(Charsets.UTF_8))
buffer.reset()
return line
}
'\n'.code -> {
val bytes = buffer.toByteArray()
buffer.reset()
return Line(bytes.toString(Charsets.UTF_8))
}
else -> {
buffer.write(read)
}
}
}
return NoLine.NOT_YET_AVAILABLE
Expand Down

0 comments on commit e476fcc

Please sign in to comment.