Skip to main content Skip to docs navigation

Convert ByteArray from/to String with Charsets: LATIN1, UTF8, UTF16...

Document not reviewed yet, might be outdated. Please, let us know if you find something invalid here.
On this page

KorIO has utilities for handling different charsets.

Charset

val ISO_8859_1: Charset
val LATIN1: SingleByteCharset
val UTF8: Charset
val UTF16_LE: UTF16Charset
val UTF16_BE: UTF16Charset
val ASCII: Charset

fun String.toByteArray(charset: Charset = UTF8): ByteArray
fun ByteArray.toString(charset: Charset): String
fun ByteArray.readStringz(o: Int, size: Int, charset: Charset = UTF8): String
fun ByteArray.readStringz(o: Int, charset: Charset = UTF8): String
fun ByteArray.readString(o: Int, size: Int, charset: Charset = UTF8): String

abstract class Charset(val name: String) {
	abstract fun encode(out: ByteArrayBuilder, src: CharSequence, start: Int = 0, end: Int = src.length)
	abstract fun decode(out: StringBuilder, src: ByteArray, start: Int = 0, end: Int = src.size)
}

open class SingleByteCharset(name: String, val conv: String) : Charset(name)

UTF8

Only UTF8 supported at the moment.

Was this article useful?