private void readIndex() throws IOException {
            // read the index entirely into memory
            if (this.keys != null) {
                return;
            }
            this.count = 0;
            this.keys = new WritableComparable[1024];
            this.positions = new long[1024];
            try {
                int skip = INDEX_SKIP;
                LongWritable position = new LongWritable();
                WritableComparable lastKey = null;
                while (true) {
                    WritableComparable k = comparator.newKey();

                    if (!index.next(k, position)) {
                        break;
                    }

                    // check order to make sure comparator is compatible
                    if (lastKey != null && comparator.compare(lastKey, k) > 0) {
                        throw new IOException("key out of order: " + k + " after " + lastKey);
                    }
                    lastKey = k;

                    if (skip > 0) {
                        skip--;
                        continue;                             // skip this entry
                    } else {
                        skip = INDEX_SKIP;                    // reset skip
                    }

                    if (count == keys.length) {                // time to grow arrays
                        int newLength = (keys.length * 3) / 2;
                        WritableComparable[] newKeys = new WritableComparable[newLength];
                        long[] newPositions = new long[newLength];
                        System.arraycopy(keys, 0, newKeys, 0, count);
                        System.arraycopy(positions, 0, newPositions, 0, count);
                        keys = newKeys;
                        positions = newPositions;
                    }

                    keys[count] = k;
                    positions[count] = position.get();
                    count++;
                }
            } catch (EOFException e) {
                LOG.warn("Unexpected EOF reading " + index
                        + " at entry #" + count + ".  Ignoring.");
            } finally {
                indexClosed = true;
                index.close();
            }
        }