axml/src/main/java/fr/xgouchet/axml/AXMLParser.java
private void processBuffer() throws IOException {

        int id;


        while (!mParsingComplete) {
            // if possible, update the buffer
            updateBuffer();

            // read the next block id
            id = readWord(mBufferStartPosition, 0);

            // switch on block type
            switch (id) {
                case WORD_START_DOCUMENT:
                    parseStartDocument();
                    break;
                case WORD_RES_TABLE:
                    parseResourceTable();
                    break;
                case WORD_STRING_TABLE:
                    parseStringTable();
                    break;
                case WORD_START_NAMESPACE:
                    parseNamespace(true);
                    break;
                case WORD_END_NAMESPACE:
                    parseNamespace(false);
                    break;
                case WORD_START_TAG:
                    parseStartTag();
                    break;
                case WORD_END_TAG:
                    parseEndTag();
                    break;
                case WORD_TEXT:
                    parseText();
                    break;
                default:
                    if (mReadBytes == 0) {
                        throw new UnknownFormatFlagsException("This document doesn't seem to be an Android XML document");
                    } else {
                        // we're encountering an unknown flag, but we have already read a few, so let's just log that
                        moveBufferPositionByWords(1);
                        logError(String.format("Unknown block id : 0x%x at position 0x%x", id, mBufferStartPosition))
                        ;
                    }
                    break;
            }

            // Check the end of document
            if (mReadBytes >= mDocSize) {
                mListener.endDocument();
                mParsingComplete = true;
            } else
                // Check end of stream
                if ((mBufferStartPosition >= mBufferEndPosition) && mEndOfStreamReached) {
                    throw new IOException("Unexpected End Of Stream");
                }
        }

    }
/**
     * The parse loop will move block by block through the input stream
     */
The parse loop will move block by block through the input stream
The parse loop will move block by block through the input stream
private void processBuffer() throws IOException {
        int id;
        while (!mParsingComplete) {
            updateBuffer();
            id = readWord(mBufferStartPosition, 0);
            switch (id) {
                case WORD_START_DOCUMENT:
                    parseStartDocument();
                    break;
                case WORD_RES_TABLE:
                    parseResourceTable();
                    break;
                case WORD_STRING_TABLE:
                    parseStringTable();
                    break;
                case WORD_START_NAMESPACE:
                    parseNamespace(true);
                    break;
                case WORD_END_NAMESPACE:
                    parseNamespace(false);
                    break;
                case WORD_START_TAG:
                    parseStartTag();
                    break;
                case WORD_END_TAG:
                    parseEndTag();
                    break;
                case WORD_TEXT:
                    parseText();
                    break;
                default:
                    if (mReadBytes == 0) {
                        throw new UnknownFormatFlagsException("This document doesn't seem to be an Android XML document");
                    } else {
                        moveBufferPositionByWords(1);
                        logError(String.format("Unknown block id : 0x%x at position 0x%x", id, mBufferStartPosition))
                        ;
                    }
                    break;
            }
            if (mReadBytes >= mDocSize) {
                mListener.endDocument();
                mParsingComplete = true;
            } else
                if ((mBufferStartPosition >= mBufferEndPosition) && mEndOfStreamReached) {
                    throw new IOException("Unexpected End Of Stream");
                }
        }
    }
private void processBuffer ( ) throws IOException { int id ; while ( ! mParsingComplete ) { updateBuffer ( ) ; id = readWord ( mBufferStartPosition , 0 ) ; switch ( id ) { case WORD_START_DOCUMENT : parseStartDocument ( ) ; break ; case WORD_RES_TABLE : parseResourceTable ( ) ; break ; case WORD_STRING_TABLE : parseStringTable ( ) ; break ; case WORD_START_NAMESPACE : parseNamespace ( true ) ; break ; case WORD_END_NAMESPACE : parseNamespace ( false ) ; break ; case WORD_START_TAG : parseStartTag ( ) ; break ; case WORD_END_TAG : parseEndTag ( ) ; break ; case WORD_TEXT : parseText ( ) ; break ; default : if ( mReadBytes == 0 ) { throw new UnknownFormatFlagsException ( "This document doesn't seem to be an Android XML document" ) ; } else { moveBufferPositionByWords ( 1 ) ; logError ( String . format ( "Unknown block id : 0x%x at position 0x%x" , id , mBufferStartPosition ) ) ; } break ; } if ( mReadBytes >= mDocSize ) { mListener . endDocument ( ) ; mParsingComplete = true ; } else if ( ( mBufferStartPosition >= mBufferEndPosition ) && mEndOfStreamReached ) { throw new IOException ( "Unexpected End Of Stream" ) ; } } }
The parse loop will move block by block through the input stream
The parse loop will move block by block through the input stream
// if possible, update the buffer // read the next block id // switch on block type // we're encountering an unknown flag, but we have already read a few, so let's just log that // Check the end of document // Check end of stream