@Override
    public Base64BinaryChunk parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
        String streamId = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_STREAM_ID);
        String nrString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_NR);
        String lastString = parser.getAttributeValue("", Base64BinaryChunk.ATTRIBUTE_LAST);
        boolean last = false;
        int nr = Integer.parseInt(nrString);

        if (lastString != null) {
            last = Boolean.parseBoolean(lastString);
        }

        String text = null;
        boolean done = false;

        while (!done) {
            XmlPullParser.Event eventType = parser.next();

            if (eventType == XmlPullParser.Event.END_ELEMENT) {
                if (parser.getName().equals(Base64BinaryChunk.ELEMENT_CHUNK)) {
                    done = true;
                } else {
                    throw new IllegalArgumentException("unexpected end tag of: " + parser.getName());
                }
            } else if (eventType == XmlPullParser.Event.TEXT_CHARACTERS) {
                text = parser.getText();
            } else {
                throw new IllegalArgumentException("unexpected eventType: " + eventType);
            }
        }

        return new Base64BinaryChunk(text, streamId, nr, last);
    }
@Test
    public void isLatsChunkParsedCorrectly() throws Exception {
        String base64Text = "2uPzi9u+tVWJd+e+y1AAAAABJRU5ErkJggg==";
        String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' nr='1' last='true'>" + base64Text + "</chunk>";

        Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
        XmlPullParser parser = PacketParserUtils.getParserFor(string);

        ExtensionElement extension = provider.parse(parser);
        assertTrue(extension instanceof Base64BinaryChunk);

        Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
        assertEquals("Stream0001", chunk.getStreamId());
        assertTrue(chunk.isLast());
        assertEquals(base64Text, chunk.getText());
        assertEquals(1, chunk.getNr());
    }