code: public final ByteBuffer encode(CharBuffer buffer) {
          try {
              return newEncoder()
                      .onMalformedInput(CodingErrorAction.REPLACE)
                      .onUnmappableCharacter(CodingErrorAction.REPLACE).encode(
                              buffer);
          } catch (CharacterCodingException ex) {
              throw new Error(ex.getMessage(), ex);
          }
      }
docs: Returns a new {@code ByteBuffer} containing the bytes encoding the characters from
  {@code buffer}.
  This method uses {@code CodingErrorAction.REPLACE}.
  
  <p>Applications should generally create a {@link CharsetEncoder} using {@link #newEncoder}
  for performance.
  
  @param buffer
  the character buffer containing the content to be encoded.
  @return the result of the encoding.