char[] decode(final ByteBuf in)
    {
        final CharBuffer charBuffer = CharBuffer.allocate(in.capacity());
        encoder.reset();
        final ByteBuffer nioBuffer = in.nioBuffer(); // Note: this NIO buffer has its position initialized on 0, even if the ByteBuffer that it's obtained from has a read-index that is higher (see OF-2872).
        encoder.decode(nioBuffer, charBuffer, false);
        final char[] buf = new char[charBuffer.position()];
        charBuffer.flip();
        charBuffer.get(buf);

        // Netty won't update the reader-index of the original buffer when its nio-buffer representation is read from. Adjust the position of the original buffer.
        in.readerIndex(in.readerIndex() + nioBuffer.position());

        return buf;
    }
Reads from the provided byte buffer all bytes that can be decoded as UTF-8 characters, and returns those
characters. The position (reader-index) of the input buffer is updated to the first byte that's not decoded.
This should allow the data to be decoded again, after additional bytes are added to the buffer. This intends
to prevent issues with multi-byte characters.

@param in The buffer from which to read.
@return UTF-8 characters that were read from the buffer.
@see <a href="https://igniterealtime.atlassian.net/browse/OF-458">issue OF-458: XMPPDecoder has a decode problem for UTF-8</a>
@see <a href="https://igniterealtime.atlassian.net/browse/OF-2814">issue OF-2814: Issue with cyrilic (any multi-byte?) characters in messages</a>
xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java