mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -07:00
Use the inputStream.
This commit is contained in:
parent
62f656fa54
commit
238a4df95b
1 changed files with 10 additions and 8 deletions
|
@ -19,15 +19,17 @@ class CountingFileRequestBody(val file: File, val contentType: String,
|
||||||
override fun contentType() = MediaType.parse(contentType)
|
override fun contentType() = MediaType.parse(contentType)
|
||||||
|
|
||||||
override fun writeTo(sink: BufferedSink) {
|
override fun writeTo(sink: BufferedSink) {
|
||||||
Okio.source(file).use { source ->
|
file.inputStream().use { fis ->
|
||||||
var total = 0L
|
Okio.source(fis).use { source ->
|
||||||
var read: Long = source.read(sink.buffer(), SEGMENT_SIZE)
|
var total = 0L
|
||||||
|
var read: Long = source.read(sink.buffer(), SEGMENT_SIZE)
|
||||||
|
|
||||||
while (read != -1L) {
|
while (read != -1L) {
|
||||||
total += read
|
total += read
|
||||||
sink.flush();
|
sink.flush();
|
||||||
listenerCallback(total)
|
listenerCallback(total)
|
||||||
read = source.read(sink.buffer(), SEGMENT_SIZE)
|
read = source.read(sink.buffer(), SEGMENT_SIZE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue