Hi folks! Is there a best alternative in Kotlin than using java nio Bytebuffer?
Copy code
val bos = ByteArrayOutputStream()
DataOutputStream(bos).use {
it.writeInt(mydata)
}
ByteBuffer.wrap(bos.toByteArray())
I was googling around but haven’t found anything really.
v
Vampire
10/05/2020, 8:11 AM
To do what?
Your end result currently is a
ByteBuffer
a
Andrea Giuliano
10/05/2020, 8:35 AM
yes I’d like to emulate an elastic byte buffer format to write data on the fly. Is the Kotlin standard approach to use ByteArray with + operator and forget about ByteArrayOutputStream, DataOutputStream and ByteBuffer?
z
Zach Klippenstein (he/him) [MOD]
10/05/2020, 2:58 PM
Are you just looking for alternative IO libraries? Okio has a much more ergonomic API imo, interops with jvm io, and is even starting to get KMP support.