Code example for CharsetDecoder

Methods: decode

0
    if (replace) {
      decoder.onMalformedInput(
          java.nio.charset.CodingErrorAction.REPLACE);
      decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    } 
    String str = decoder.decode(utf8).toString();
    // set decoder back to its default value: REPORT 
    if (replace) {
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    } 
    return str;
  } 
 
  /** 
   * Converts the provided String to bytes using the 
   * UTF-8 encoding. If the input is malformed, 
   * invalid chars are replaced by a default value. 
   * @return ByteBuffer: bytes stores at ByteBuffer.array()  
   *                     and length is ByteBuffer.limit()