Code example for CharsetDecoder

Methods: averageCharsPerByte, onMalformedInput, onUnmappableCharacter, reset

0
this.channel = channel;
    this.decoder = decoder;
 
    // JDK reports errors, so we do the same. 
    decoder.onMalformedInput(CodingErrorAction.REPORT);
    decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    decoder.reset();
 
    int size = (minBufferCap == -1) ? DEFAULT_BUFFER_CAP : minBufferCap;
 
    // Allocates the buffers and prepares them for reading, because that is the 
    // first operation being done on them. 
    byteBuffer = ByteBuffer.allocate(size);
    byteBuffer.flip();
    charBuffer = CharBuffer.allocate((int) (size * decoder.averageCharsPerByte()));
  } 
 
  public int read(char[] buf, int offset, int count) throws IOException
  { 
    synchronized (lock)