Code example for CharsetDecoder

Methods: decodeflushreset

0
    // test illegal states for two decode method with endOfInput is true 
    public void testDecodeTrueIllegalState() throws CharacterCodingException {
        ByteBuffer in = ByteBuffer.wrap(new byte[] { 98, 98 });
        CharBuffer out = CharBuffer.allocate(100);
        // Normal case: just created 
        decoder.decode(in, out, true);
        in.rewind();
        out.rewind();
 
        // Normal case: just after decode with that endOfInput is true 
        decoder.reset();
        decoder.decode(in, CharBuffer.allocate(30), true);
        in.rewind();
        decoder.decode(in, out, true);
        in.rewind();
        out.rewind();
 
        // Normal case:just after decode with that endOfInput is false 
        decoder.reset();
        decoder.decode(in, CharBuffer.allocate(30), false);
        in.rewind();
        decoder.decode(in, out, true);
        in.rewind();
        out.rewind();
 
        // Illegal state: just after flush 
        decoder.reset();
        decoder.decode(in, CharBuffer.allocate(30), true);
        decoder.flush(CharBuffer.allocate(10));
        in.rewind();
        try { 
            decoder.decode(in, out, true);
            fail("should illegal state");
        } catch (IllegalStateException e) {
        } 
        in.rewind();
        out.rewind();
Contextual code suggestions in your IDE  Get Codota for Java