import java.nio.*;
import java.nio.charset.*;
class CharsetDecoderTest {
public static void main(String[] args) {
Charset charset = Charset.forName("ASCII");
CharsetDecoder decoder = charset.newDecoder();
byte[] tab = {(byte)'c',(byte)'r',(byte)'é',(byte)'é'};
ByteBuffer byteB = ByteBuffer.wrap(tab);
byteB.limit(1);
CharBuffer charB = CharBuffer.allocate(tab.length);
CoderResult cr = decoder.decode(byteB,charB,false);
System.out.println(cr); charB.flip();
System.out.println(charB); charB.position(charB.limit());
charB.limit(charB.capacity());
byteB.limit(byteB.capacity());
decoder.onMalformedInput(CodingErrorAction.REPLACE);
decoder.replaceWith("*");
cr = decoder.decode(byteB,charB,true);
decoder.flush(charB);
charB.flip();
System.out.println(charB); }
}