Hi folks! Is there a best alternative in Kotlin th...
# announcements
a
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
To do what? Your end result currently is a
ByteBuffer
a
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
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.
👍 1