public TFileIndex(int entryCount,DataInput in,BytesComparator comparator) throws IOException {
  index=new ArrayList<TFileIndexEntry>(entryCount);
  recordNumIndex=new ArrayList<Long>(entryCount);
  int size=Utils.readVInt(in);
  if (size > 0) {
    byte[] buffer=new byte[size];
    in.readFully(buffer);
    DataInputStream firstKeyInputStream=new DataInputStream(new ByteArrayInputStream(buffer,0,size));
    int firstKeyLength=Utils.readVInt(firstKeyInputStream);
    firstKey=new ByteArray(new byte[firstKeyLength]);
    firstKeyInputStream.readFully(firstKey.buffer());
    for (int i=0; i < entryCount; i++) {
      size=Utils.readVInt(in);
      if (buffer.length < size) {
        buffer=new byte[size];
      }
      in.readFully(buffer,0,size);
      TFileIndexEntry idx=new TFileIndexEntry(new DataInputStream(new ByteArrayInputStream(buffer,0,size)));
      index.add(idx);
      sum+=idx.entries();
      recordNumIndex.add(sum);
    }
  }
 else {
    if (entryCount != 0) {
      throw new RuntimeException("Internal error");
    }
  }
  this.comparator=comparator;
}

public TFileIndex ( int entryCount , DataInput in , BytesComparator comparator ) throws IOException { index = new ArrayList < TFileIndexEntry > ( entryCount ) ; recordNumIndex = new ArrayList < Long > ( entryCount ) ; int size = Utils . readVInt ( in ) ; if ( size > 0 ) { byte [ ] buffer = new byte [ size ] ; in . readFully ( buffer ) ; DataInputStream firstKeyInputStream = new DataInputStream ( new ByteArrayInputStream ( buffer , 0 , size ) ) ; int firstKeyLength = Utils . readVInt ( firstKeyInputStream ) ; firstKey = new ByteArray ( new byte [ firstKeyLength ] ) ; firstKeyInputStream . readFully ( firstKey . buffer ( ) ) ; for ( int i = 0 ; i < entryCount ; i ++ ) { size = Utils . readVInt ( in ) ; if ( buffer . length < size ) { buffer = new byte [ size ] ; } in . readFully ( buffer , 0 , size ) ; TFileIndexEntry idx = new TFileIndexEntry ( new DataInputStream ( new ByteArrayInputStream ( buffer , 0 , size ) ) ) ; index . add ( idx ) ; sum += idx . entries ( ) ; recordNumIndex . add ( sum ) ; } } else { if ( entryCount != 0 ) { throw new RuntimeException ( "Internal error" ) ; } } this . comparator = comparator ; }
for reading from file .
