byteSuffix
The string that immediately follows the two-digit hexadecimal representation of each byte.
When formatting, this string is used as a suffix for the hexadecimal representation of each byte.
When parsing, the hexadecimal representation of each byte must be suffixed by this string. The parsing of this suffix is performed in a case-insensitive manner.
Since Kotlin
1.9Samples
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
}