1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Use the inputStream.

This commit is contained in:
Cedric Beust 2016-03-11 22:04:36 +04:00
parent 62f656fa54
commit 238a4df95b

View file

@ -19,15 +19,17 @@ class CountingFileRequestBody(val file: File, val contentType: String,
override fun contentType() = MediaType.parse(contentType)
override fun writeTo(sink: BufferedSink) {
Okio.source(file).use { source ->
var total = 0L
var read: Long = source.read(sink.buffer(), SEGMENT_SIZE)
file.inputStream().use { fis ->
Okio.source(fis).use { source ->
var total = 0L
var read: Long = source.read(sink.buffer(), SEGMENT_SIZE)
while (read != -1L) {
total += read
sink.flush();
listenerCallback(total)
read = source.read(sink.buffer(), SEGMENT_SIZE)
while (read != -1L) {
total += read
sink.flush();
listenerCallback(total)
read = source.read(sink.buffer(), SEGMENT_SIZE)
}
}
}
}