byteSuffix
Defines BytesHexFormat.byteSuffix of the format being built, empty string by default.
The string must not contain line feed (LF) and carriage return (CR) characters.
Refer to BytesHexFormat.byteSuffix for details about how this format option affects the formatting and parsing results.
Since Kotlin
1.9Throws
if a string containing LF or CR character is assigned to this property.
Samples
import kotlin.test.*
fun main() {
//sampleStart
val data = ByteArray(4) { it.toByte() }
// By default, the byteSuffix is an empty string, so bytes are formatted without any suffix.
println(data.toHexString()) // 00010203
println("\"00010203\".hexToByteArray().contentEquals(data) is ${"00010203".hexToByteArray().contentEquals(data)}") // true
// Specifying a custom byte suffix, a semicolon in this case, to follow each byte.
val byteSuffixFormat = HexFormat {
bytes.byteSuffix = ";"
}
println(data.toHexString(byteSuffixFormat)) // 00;01;02;03;
println("\"00;01;02;03;\".hexToByteArray(byteSuffixFormat).contentEquals(data) is ${"00;01;02;03;".hexToByteArray(byteSuffixFormat).contentEquals(data)}") // true
// Parsing fails due to incorrect byte suffix.
// In this case, the input string is lacking the necessary byte suffixes.
// "00010203".hexToByteArray(byteSuffixFormat) // will fail with IllegalArgumentException
//sampleEnd
}