IAmRasputin
11/27/2018, 6:50 PMInputStream
and loops over it, reading fixed-size chunks of bytes from it. However, it uses the Java idiom where assignment is used as an expression:
byte[] buffer = new byte[CHUNK_SIZE];
while ((bytesRead = stream.read(buffer, 0, CHUNK_SIZE)) != -1) {
// do things
}
Kotlin, of course, does not like this, as assignments are not expressions. Is there an idiomatic way to iterate over sized chunks from a stream, like lines
but less text-oriented? I could call read
inside and outside the loop, but I'd like to avoid that if possible.fred.deschenes
11/27/2018, 8:18 PMreadBytes
extension on InputStreams that does the same thing but with a ByteArrayOutputStreamfred.deschenes
11/27/2018, 8:19 PMwhile
unfortunetelyfred.deschenes
11/27/2018, 8:20 PMcopyTo
extension is doing anyway:
var bytes = read(buffer)
while (bytes >= 0) {
...
bytes = read(buffer)
}
IAmRasputin
11/27/2018, 8:46 PMfred.deschenes
11/27/2018, 8:56 PM