toString

open override fun toString(): String

Converts the buffer's contents into a string decoding bytes using the default charset. The length of the new String is a function of the charset, and hence may not be equal to the size of the buffer.

This method always replaces malformed-input and unmappable-character sequences with the default replacement string for the default charset. The CharsetDecoder class should be used when more control over the decoding process is required.

Return

String decoded from the buffer's contents.

Since

1.1

See also


fun toString(charsetName: String): String

Converts the buffer's contents into a string by decoding the bytes using the named charset.

This method is equivalent to #toString(charset) that takes a charset.

An invocation of this method of the form

{@snippet lang=java :

  • ByteArrayOutputStream b;
  • b.toString("UTF-8")
  • }

behaves in exactly the same way as the expression

{@snippet lang=java :

  • ByteArrayOutputStream b;
  • b.toString(StandardCharsets.UTF_8)
  • }

Return

String decoded from the buffer's contents.

Since

1.1

Parameters

charsetName

the name of a supported charset

Throws

If the named charset is not supported


fun toString(charset: Charset): String

Converts the buffer's contents into a string by decoding the bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

This method always replaces malformed-input and unmappable-character sequences with the charset's default replacement string. The [ ] class should be used when more control over the decoding process is required.

Return

String decoded from the buffer's contents.

Since

10

Parameters

charset

the charset to be used to decode the bytes