public static int firstDocIdOfChunk(byte[] bytestream, int chunkNum, int chunkID) {//return the first value of the chunk
        int n = 0;
        int offset = chunkNum;//offset of docId is equal to  chunk number of this inverted list
        for(int i=0; i< chunkID; i++) {
        	offset += (int)bytestream[i] & 0xff;
        }
        for (int i=offset; ; i++) {
            if ( (bytestream[i] & (byte)(0x80)) == 0 ){
                    n = 128*n + bytestream[i];
                    return n;
            }
            else {
                    byte b = (byte)(bytestream[i] & 0x7F); //Achieves the effect of -= 128. 
                    n = 128*n + b;
            }
        }
    }