@Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        AsyncByteArrayFeeder streamFeeder = streamReader.getInputFeeder();
        logger.info("Decoding XMPP data.. ");

        byte[] buffer = new byte[in.readableBytes()];
        in.readBytes(buffer);
        logger.debug("Buffer length: " + buffer.length);
        try {
            streamFeeder.feedInput(buffer, 0, buffer.length);
        } catch (XMLStreamException exception) {
            logger.info(exception.getMessage());
            in.skipBytes(in.readableBytes());
            logger.info("Bytes skipped");
            throw exception;
        }

        while (streamReader.hasNext() && streamReader.next() != AsyncXMLStreamReader.EVENT_INCOMPLETE) {
            out.add(allocator.allocate(streamReader));
        }

    }
@Test
    public void testDecodeXmppStanza() throws Exception {
        XmlStreamDecoder decoder = new XmlStreamDecoder();
        ByteBuf buffer = Unpooled.buffer();
        buffer.writeBytes(subscribeMsg.getBytes(Charsets.UTF_8));
        List<Object> list = Lists.newArrayList();
        decoder.decode(new ChannelHandlerContextAdapter(), buffer, list);
        assertThat(list.size(), is(10));
        list.forEach(object -> {
            assertThat(object, is(instanceOf(XMLEvent.class)));
        });
        assertThat(((XMLEvent) list.get(0)).isStartDocument(), is(true));
        XMLEvent secondEvent = (XMLEvent) list.get(1);
        assertThat(secondEvent.isStartElement(), is(true));
        StartElement secondEventAsStartElement = (StartElement) secondEvent;
        assertThat(secondEventAsStartElement.getName().getLocalPart(), is("iq"));
        assertThat(Lists.newArrayList(secondEventAsStartElement.getAttributes()).size(), is(4));
        assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("type")).getValue(), is("set"));
        assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("from")).getValue(),
                   is("test@xmpp.org"));
        assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("to")).getValue(),
                   is("xmpp.onosproject.org"));
        assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("id")).getValue(),
                   is("sub1"));
        XMLEvent fourthEvent = (XMLEvent) list.get(3);
        assertThat(fourthEvent.isStartElement(), is(true));
        StartElement fourthEventAsStartElement = (StartElement) fourthEvent;
        assertThat(fourthEventAsStartElement.getName().getLocalPart(), is("pubsub"));
        assertThat(fourthEventAsStartElement.getNamespaceURI(""),
                   is("http://jabber.org/protocol/pubsub"));
        XMLEvent fifthEvent = (XMLEvent) list.get(5);
        assertThat(fifthEvent.isStartElement(), is(true));
        StartElement fifthEventAsStartElement = (StartElement) fifthEvent;
        assertThat(fifthEventAsStartElement.getName().getLocalPart(), is("subscribe"));
        assertThat(fifthEventAsStartElement.getAttributeByName(QName.valueOf("node")).getValue(), is("test"));
        XMLEvent sixthEvent = (XMLEvent) list.get(6);
        assertThat(sixthEvent.isEndElement(), is(true));
        EndElement sixthEventAsEndElement = (EndElement) sixthEvent;
        assertThat(sixthEventAsEndElement.getName().getLocalPart(), is("subscribe"));
        XMLEvent seventhEvent = (XMLEvent) list.get(8);
        assertThat(seventhEvent.isEndElement(), is(true));
        EndElement seventhEventAsEndElement = (EndElement) seventhEvent;
        assertThat(seventhEventAsEndElement.getName().getLocalPart(), is("pubsub"));
        XMLEvent eighthEvent = (XMLEvent) list.get(9);
        assertThat(eighthEvent.isEndElement(), is(true));
        EndElement eighthEventAsEndElement = (EndElement) eighthEvent;
        assertThat(eighthEventAsEndElement.getName().getLocalPart(), is("iq"));
    }