What is a proper replacement for the now-deprecate...
# ktor
s
What is a proper replacement for the now-deprecated
<http://io.ktor.utils.io|io.ktor.utils.io>.core.String
constructor here? I need to decode ASCII.
1
a
You can create a decoder with
Charsets.ISO_8859_1.newDecoder()
to decode a
Source
into a string. Here is an example:
Copy code
val bytes = ByteArray(1024) { 65 }
val buffer = Buffer()
buffer.write(bytes)
val string = Charsets.ISO_8859_1.newDecoder().decode(buffer)
s
Can I cache and reuse "Charsets.ISO_8859_1.newDecoder()" ?
a
Yes, you can.
s
So this is safe?
Copy code
private val decoder = Charsets.ISO_8859_1.newDecoder()

internal actual fun ByteArray.decodeLatin1BytesToString(): String {

    val buffer = Buffer()
    buffer.write(this)

    return decoder.decode(buffer)
}
a
It should be safe
s
Thank you for your help! 🙂