public static StringPool readStringPool(ByteBuffer buffer, StringPoolHeader stringPoolHeader) {

        long beginPos = buffer.position();
        int[] offsets = new int[stringPoolHeader.getStringCount()];
        // read strings offset
        if (stringPoolHeader.getStringCount() > 0) {
            for (int idx = 0; idx < stringPoolHeader.getStringCount(); idx++) {
                offsets[idx] = Unsigned.toUInt(Buffers.readUInt(buffer));
            }
        }
        // read flag
        // the string index is sorted by the string values if true
        boolean sorted = (stringPoolHeader.getFlags() & StringPoolHeader.SORTED_FLAG) != 0;
        // string use utf-8 format if true, otherwise utf-16
        boolean utf8 = (stringPoolHeader.getFlags() & StringPoolHeader.UTF8_FLAG) != 0;

        // read strings. the head and metas have 28 bytes
        long stringPos = beginPos + stringPoolHeader.getStringsStart() - stringPoolHeader.getHeaderSize();
        Buffers.position(buffer, stringPos);

        StringPoolEntry[] entries = new StringPoolEntry[offsets.length];
        for (int i = 0; i < offsets.length; i++) {
            entries[i] = new StringPoolEntry(i, stringPos + Unsigned.toLong(offsets[i]));
        }

        String lastStr = null;
        long lastOffset = -1;
        StringPool stringPool = new StringPool(stringPoolHeader.getStringCount());
        for (StringPoolEntry entry : entries) {
            if (entry.getOffset() == lastOffset) {
                stringPool.set(entry.getIdx(), lastStr);
                continue;
            }

            Buffers.position(buffer, entry.getOffset());
            lastOffset = entry.getOffset();
            String str = ParseUtils.readString(buffer, utf8);
            lastStr = str;
            stringPool.set(entry.getIdx(), str);
        }

        // read styles
        if (stringPoolHeader.getStyleCount() > 0) {
            // now we just skip it
        }

        Buffers.position(buffer, beginPos + stringPoolHeader.getBodySize());

        return stringPool;
    }
public static StringPool readStringPool ( ByteBuffer buffer , StringPoolHeader stringPoolHeader ) { long beginPos = buffer . position ( ) ; int [ ] offsets = new int [ stringPoolHeader . getStringCount ( ) ] ; if ( stringPoolHeader . getStringCount ( ) > 0 ) { for ( int idx = 0 ; idx < stringPoolHeader . getStringCount ( ) ; idx ++ ) { offsets [ idx ] = Unsigned . toUInt ( Buffers . readUInt ( buffer ) ) ; } } boolean sorted = ( stringPoolHeader . getFlags ( ) & StringPoolHeader . SORTED_FLAG ) != 0 ; boolean utf8 = ( stringPoolHeader . getFlags ( ) & StringPoolHeader . UTF8_FLAG ) != 0 ; long stringPos = beginPos + stringPoolHeader . getStringsStart ( ) - stringPoolHeader . getHeaderSize ( ) ; Buffers . position ( buffer , stringPos ) ; StringPoolEntry [ ] entries = new StringPoolEntry [ offsets . length ] ; for ( int i = 0 ; i < offsets . length ; i ++ ) { entries [ i ] = new StringPoolEntry ( i , stringPos + Unsigned . toLong ( offsets [ i ] ) ) ; } String lastStr = null ; long lastOffset = - 1 ; StringPool stringPool = new StringPool ( stringPoolHeader . getStringCount ( ) ) ; for ( StringPoolEntry entry : entries ) { if ( entry . getOffset ( ) == lastOffset ) { stringPool . set ( entry . getIdx ( ) , lastStr ) ; continue ; } Buffers . position ( buffer , entry . getOffset ( ) ) ; lastOffset = entry . getOffset ( ) ; String str = ParseUtils . readString ( buffer , utf8 ) ; lastStr = str ; stringPool . set ( entry . getIdx ( ) , str ) ; } if ( stringPoolHeader . getStyleCount ( ) > 0 ) { } Buffers . position ( buffer , beginPos + stringPoolHeader . getBodySize ( ) ) ; return stringPool ; }
read String pool, for apk binary xml file and resource table.