encode

Convenience method that encodes Unicode characters into bytes in this charset.

An invocation of this method upon a charset cs returns the same result as the expression

{@snippet lang=java :

  • cs.newEncoder()
  •   .onMalformedInput(CodingErrorAction.REPLACE)
  •   .onUnmappableCharacter(CodingErrorAction.REPLACE)
  •   .encode(bb);
  • }

except that it is potentially more efficient because it can cache encoders between successive invocations.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement string. In order to detect such sequences, use the method directly.

Return

A byte buffer containing the encoded characters

Parameters

cb

The char buffer to be encoded