Exemplo n.º 1
0
        /**
         * Reads whole (including chunk type) string block from stream.
         * Stream must be at the chunk type.
         */
        public static StringBlock read(IntReader reader)
        {
            ChunkUtil.readCheckType(reader, CHUNK_TYPE);

            int chunkSize        = reader.readInt();
            int stringCount      = reader.readInt();
            int styleOffsetCount = reader.readInt();

            /*?*/ reader.readInt();
            int stringsOffset = reader.readInt();
            int stylesOffset  = reader.readInt();

            StringBlock block = new StringBlock();

            block.m_stringOffsets = reader.readIntArray(stringCount);
            if (styleOffsetCount != 0)
            {
                block.m_styleOffsets = reader.readIntArray(styleOffsetCount);
            }

            {
                int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset;
                if ((size % 4) != 0)
                {
                    throw new IOException("String data size is not multiple of 4 (" + size + ").");
                }

                block.m_strings = reader.readIntArray(size / 4);
            }

            if (stylesOffset != 0)
            {
                int size = (chunkSize - stylesOffset);
                if ((size % 4) != 0)
                {
                    throw new IOException("Style data size is not multiple of 4 (" + size + ").");
                }
                block.m_styles = reader.readIntArray(size / 4);
            }

            return(block);
        }
Exemplo n.º 2
0
        private void doNext()
        {
            // Delayed initialization.
            if (m_strings == null)
            {
                ChunkUtil.readCheckType(m_reader, CHUNK_AXML_FILE);
                /*chunkSize*/
                m_reader.skipInt();
                m_strings = StringBlock.read(m_reader);
                m_namespaces.increaseDepth();
                m_operational = true;
            }

            if (m_event == END_DOCUMENT)
            {
                return;
            }

            int tempEvent = m_event;

            resetEventInfo();

            while (true)
            {
                if (m_decreaseDepth)
                {
                    m_decreaseDepth = false;
                    m_namespaces.decreaseDepth();
                }

                // Fake END_DOCUMENT event.
                if (tempEvent == END_TAG && m_namespaces.getDepth() == 1 && m_namespaces.getCurrentCount() == 0)
                {
                    m_event = END_DOCUMENT;
                    break;
                }

                int chunkType;
                if (tempEvent == START_DOCUMENT)
                {
                    // Fake event, see CHUNK_XML_START_TAG handler.
                    chunkType = CHUNK_XML_START_TAG;
                }
                else
                {
                    chunkType = m_reader.readInt();
                }

                if (chunkType == CHUNK_RESOURCEIDS)
                {
                    int chunkSize = m_reader.readInt();
                    if (chunkSize < 8 || (chunkSize % 4) != 0)
                    {
                        throw new IOException("Invalid resource ids size (" + chunkSize + ").");
                    }
                    m_resourceIDs = m_reader.readIntArray(chunkSize / 4 - 2);
                    continue;
                }

                if (chunkType < CHUNK_XML_FIRST || chunkType > CHUNK_XML_LAST)
                {
                    throw new IOException("Invalid chunk type (" + chunkType + ").");
                }

                // Fake START_DOCUMENT event.
                if (chunkType == CHUNK_XML_START_TAG && tempEvent == -1)
                {
                    m_event = START_DOCUMENT;
                    break;
                }

                // Common header.
                /*chunkSize*/
                m_reader.skipInt();
                int lineNumber = m_reader.readInt();
                /*0xFFFFFFFF*/
                m_reader.skipInt();

                if (chunkType == CHUNK_XML_START_NAMESPACE ||
                    chunkType == CHUNK_XML_END_NAMESPACE)
                {
                    if (chunkType == CHUNK_XML_START_NAMESPACE)
                    {
                        int prefix = m_reader.readInt();
                        int uri    = m_reader.readInt();
                        m_namespaces.push(prefix, uri);
                    }
                    else
                    {
                        /*prefix*/
                        m_reader.skipInt();
                        /*uri*/
                        m_reader.skipInt();
                        m_namespaces.pop();
                    }
                    continue;
                }

                m_lineNumber = lineNumber;

                if (chunkType == CHUNK_XML_START_TAG)
                {
                    m_namespaceUri = m_reader.readInt();
                    m_name         = m_reader.readInt();
                    /*flags?*/
                    m_reader.skipInt();
                    int attributeCount = m_reader.readInt();
                    m_idAttribute    = (unchecked ((int)(uint)attributeCount >> 16)) - 1;
                    attributeCount  &= 0xFFFF;
                    m_classAttribute = m_reader.readInt();
                    m_styleAttribute = (unchecked ((int)(uint)m_classAttribute >> 16)) - 1;
                    m_classAttribute = (m_classAttribute & 0xFFFF) - 1;
                    m_attributes     = m_reader.readIntArray(attributeCount * ATTRIBUTE_LENGHT);
                    for (int i = ATTRIBUTE_IX_VALUE_TYPE; i < m_attributes.Length;)
                    {
                        m_attributes[i] = (unchecked ((int)(uint)m_attributes[i] >> 24));
                        i += ATTRIBUTE_LENGHT;
                    }
                    m_namespaces.increaseDepth();
                    m_event = START_TAG;
                    break;
                }

                if (chunkType == CHUNK_XML_END_TAG)
                {
                    m_namespaceUri  = m_reader.readInt();
                    m_name          = m_reader.readInt();
                    m_event         = END_TAG;
                    m_decreaseDepth = true;
                    break;
                }

                if (chunkType == CHUNK_XML_TEXT)
                {
                    m_name = m_reader.readInt();
                    /*?*/
                    m_reader.skipInt();
                    /*?*/
                    m_reader.skipInt();
                    m_event = TEXT;
                    break;
                }
            }
        }