h2/src/main/org/h2/mvstore/Page.java
/**
     * Read the page from the buffer.
     *
     * @param buff the buffer
     * @param chunkId the chunk id
     * @param offset the offset within the chunk
     * @param maxLength the maximum length
     */
Read the page from the buffer.
@param buff the buffer
@param chunkId the chunk id
@param offset the offset within the chunk
@param maxLength the maximum length
Read the page from the buffer . @param buff the buffer @param chunkId the chunk id @param offset the offset within the chunk @param maxLength the maximum length
void read(ByteBuffer buff, int chunkId, int offset, int maxLength) {
        int start = buff.position();
        int pageLength = buff.getInt();
        if (pageLength > maxLength) {
            throw DataUtils.newIllegalStateException(
                    DataUtils.ERROR_FILE_CORRUPT,
                    "File corrupted, expected page length =< {0}, got {1}",
                    maxLength, pageLength);
        }
        short check = buff.getShort();
        int mapId = DataUtils.readVarInt(buff);
        if (mapId != map.getId()) {
            throw DataUtils.newIllegalStateException(
                    DataUtils.ERROR_FILE_CORRUPT,
                    "File corrupted, expected map id {0}, got {1}",
                    map.getId(), mapId);
        }
        int checkTest = DataUtils.getCheckValue(chunkId)
                ^ DataUtils.getCheckValue(offset)
                ^ DataUtils.getCheckValue(pageLength);
        if (check != (short) checkTest) {
            throw DataUtils.newIllegalStateException(
                    DataUtils.ERROR_FILE_CORRUPT,
                    "File corrupted, expected check value {0}, got {1}",
                    checkTest, check);
        }
        int len = DataUtils.readVarInt(buff);
        keys = new Object[len];
        keyCount = len;
        int type = buff.get();
        boolean node = (type & 1) == DataUtils.PAGE_TYPE_NODE;
        boolean compressed = (type & DataUtils.PAGE_COMPRESSED) != 0;
        if (compressed) {
            Compressor compressor = map.getStore().getCompressor();
            int lenAdd = DataUtils.readVarInt(buff);
            int compLen = pageLength + start - buff.position();
            byte[] comp = DataUtils.newBytes(compLen);
            buff.get(comp);
            int l = compLen + lenAdd;
            buff = ByteBuffer.allocate(l);
            compressor.expand(comp, 0, compLen, buff.array(), buff.arrayOffset(), l);
        }
        DataType keyType = map.getKeyType();
        for (int i = 0; i < len; i++) {
            Object k = keyType.read(buff);
            keys[i] = k;
        }
        if (node) {
            childCount = len + 1;
            children = new long[len + 1];
            for (int i = 0; i <= len; i++) {
                children[i] = buff.getLong();
            }
            childrenPages = new Page[len + 1];
            counts = new long[len + 1];
            long total = 0;
            for (int i = 0; i <= len; i++) {
                long s = DataUtils.readVarLong(buff);
                total += s;
                counts[i] = s;
            }
            totalCount = total;
        } else {
            values = new Object[len];
            DataType valueType = map.getValueType();
            for (int i = 0; i < len; i++) {
                Object v = valueType.read(buff);
                values[i] = v;
            }
            totalCount = len;
        }
        memory = calculateMemory();
    }
void read ( ByteBuffer buff , int chunkId , int offset , int maxLength ) { int start = buff . position ( ) ; int pageLength = buff . getInt ( ) ; if ( pageLength > maxLength ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_FILE_CORRUPT , "File corrupted, expected page length =< {0}, got {1}" , maxLength , pageLength ) ; } short check = buff . getShort ( ) ; int mapId = DataUtils . readVarInt ( buff ) ; if ( mapId != map . getId ( ) ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_FILE_CORRUPT , "File corrupted, expected map id {0}, got {1}" , map . getId ( ) , mapId ) ; } int checkTest = DataUtils . getCheckValue ( chunkId ) ^ DataUtils . getCheckValue ( offset ) ^ DataUtils . getCheckValue ( pageLength ) ; if ( check != ( short ) checkTest ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_FILE_CORRUPT , "File corrupted, expected check value {0}, got {1}" , checkTest , check ) ; } int len = DataUtils . readVarInt ( buff ) ; keys = new Object [ len ] ; keyCount = len ; int type = buff . get ( ) ; boolean node = ( type & 1 ) == DataUtils . PAGE_TYPE_NODE ; boolean compressed = ( type & DataUtils . PAGE_COMPRESSED ) != 0 ; if ( compressed ) { Compressor compressor = map . getStore ( ) . getCompressor ( ) ; int lenAdd = DataUtils . readVarInt ( buff ) ; int compLen = pageLength + start - buff . position ( ) ; byte [ ] comp = DataUtils . newBytes ( compLen ) ; buff . get ( comp ) ; int l = compLen + lenAdd ; buff = ByteBuffer . allocate ( l ) ; compressor . expand ( comp , 0 , compLen , buff . array ( ) , buff . arrayOffset ( ) , l ) ; } DataType keyType = map . getKeyType ( ) ; for ( int i = 0 ; i < len ; i ++ ) { Object k = keyType . read ( buff ) ; keys [ i ] = k ; } if ( node ) { childCount = len + 1 ; children = new long [ len + 1 ] ; for ( int i = 0 ; i <= len ; i ++ ) { children [ i ] = buff . getLong ( ) ; } childrenPages = new Page [ len + 1 ] ; counts = new long [ len + 1 ] ; long total = 0 ; for ( int i = 0 ; i <= len ; i ++ ) { long s = DataUtils . readVarLong ( buff ) ; total += s ; counts [ i ] = s ; } totalCount = total ; } else { values = new Object [ len ] ; DataType valueType = map . getValueType ( ) ; for ( int i = 0 ; i < len ; i ++ ) { Object v = valueType . read ( buff ) ; values [ i ] = v ; } totalCount = len ; } memory = calculateMemory ( ) ; }
Read the page from the buffer.
Read the page from the buffer .