ByteBufferExample { public CharBuffer decode() throws CharacterCodingException { Charset latin1 = Charset.forName("ISO-8859-1"); CharsetDecoder decoder = latin1.newDecoder(); CharBuffer charBuffer = decoder.decode(this.buffer.asReadOnlyBuffer()); return charBuffer; }  ByteBuffer put(byte b); ByteBuffer put(byte src[]); ByteBuffer put(byte src[], int offset, int length); ByteBuffer put(ByteBuffer src); ByteBuffer put(int index, byte b); byte get(); CharBuffer decode(); void enCode(CharBuffer cb);  }
@Test public void deCode() throws CharacterCodingException { ByteBufferExample buffer = new ByteBufferExample(); buffer.put((byte)'a'); buffer.put("b".getBytes()); buffer.put((byte)'c'); buffer.put((byte)'d'); buffer.buffer.flip(); CharBuffer cb = buffer.decode(); Assert.assertEquals("abcd", cb.toString()); }