@Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        // Get the XML parser from the channel
        XMLLightweightParser parser = ctx.channel().attr(NettyConnectionHandler.XML_PARSER).get();

        // Check that the stanza constructed by the parser is not bigger than 1 Megabyte. For security reasons
        // we will abort parsing when 1 Mega of queued chars was found.
        if (parser.isMaxBufferSizeExceeded()) {
            // Clear out the buffer to prevent endless exceptions being thrown while the connection is closed.
            // De-allocation of the buffer from this channel will occur following the channel closure, so there is
            // no need to call in.release() as this will cause an IllegalReferenceCountException.
            in.clear();
            NettyConnection connection = ctx.channel().attr(CONNECTION).get();
            Log.warn("Maximum buffer size was exceeded, closing connection: " + connection);
            connection.close(new StreamError(StreamError.Condition.policy_violation, "Maximum stanza length exceeded"));
            return;
        }

        // Parse as many stanzas as possible from the received data
        parser.read(in);

        // Add any decoded messages to our outbound list to be processed by subsequent channelRead() events
        if (parser.areThereMsgs()) {
            out.addAll(Arrays.asList(parser.getMsgs()));
        }
    }
Decoder that parses ByteBuffers and generates XML stanzas. Generated
stanzas are then passed to the next filters.
xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyXMPPDecoder.java