Colton Idle
10/24/2023, 6:21 PMunexpected end of stream
error. This is roughly my code that takes the bufferedReader from okhttp. Anything look obviously bad here?
suspend fun deleteAllThenInsertAllLines(bufferedReader: BufferedReader) =
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
myQueries.transaction {
myQueries.deleteAll()
var currentLine: String? = null
try {
while (bufferedReader.readLine().also { currentLine = it } != null) {
myQueries.insert(currentLine)
}
} catch (e: Exception) {
printlin("Exception! Failed on $currentLine with ${e.message}")
}
}
}
Daniel Perez
10/24/2023, 6:51 PMSource
and Sink
API's.
My understanding of Okio is that it's supposed to be a better, safer, and faster wrapper on top of <http://java.io|java.io>
API's and it's something OkHttp
depends on already
Definitely look at it first though, I don't want to just recommended using a tool that may just end up being overkill for a simple fix.ephemient
10/24/2023, 7:16 PM.useLines {}
is preferred if possible. .readlnOrNull()
is a better name for .readLine()
anyhowColton Idle
10/24/2023, 7:21 PMephemient
10/24/2023, 7:26 PMuseLines
,
bufferedReader.useLines { lines ->
for (line in lines) {
// can suspend
linesSequence()
if you really don't want to close it for some reason…Colton Idle
10/25/2023, 3:05 AMChunked transfer encoding
https://stackoverflow.com/a/58217819ephemient
10/25/2023, 4:47 AM