@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 testDecodeStreamClose() throws Exception {
        XmlStreamDecoder decoder = new XmlStreamDecoder();
        // open stream
        ByteBuf buffer1 = Unpooled.buffer();
        buffer1.writeBytes(streamOpenMsg.getBytes(Charsets.UTF_8));
        List<Object> list1 = Lists.newArrayList();
        decoder.decode(new ChannelHandlerContextAdapter(), buffer1, list1);

        // close stream
        ByteBuf buffer2 = Unpooled.buffer();
        buffer2.writeBytes(streamCloseMsg.getBytes(Charsets.UTF_8));
        List<Object> list2 = Lists.newArrayList();
        decoder.decode(new ChannelHandlerContextAdapter(), buffer2, list2);
        list2.forEach(object -> {
            assertThat(object, is(instanceOf(XMLEvent.class)));
        });
        assertThat(list2.size(), is(1));
        assertThat(((XMLEvent) list2.get(0)).isEndElement(), is(true));
    }