private void readSegmentIndex(ReadStream is, Segment10 segment)
    throws IOException
  {
    int address = segment.length() - BLOCK_SIZE;
    
    TempBuffer tBuf = TempBuffer.create();
    byte []buffer = tBuf.buffer();
    
    is.position(address);
    is.read(buffer, 0, BLOCK_SIZE);
    
    int tail = BitsUtil.readInt16(buffer, FOOTER_OFFSET);
    
    if (tail < TABLE_KEY_SIZE + 8 || tail > BLOCK_SIZE - 8) {
      return;
    }
    
    int offset = INDEX_OFFSET;
    
    while (offset < tail) {
      int type = buffer[offset++] & 0xff;
      
      int pid = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int nextPid = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int entryAddress = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int entryLength = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      if (pid <= 1) {
        System.out.println("INVALID_PID: " + pid);
        return;
      }
      
      switch (PageType10.values()[type]) {
      case LEAF:
        addLeaf(segment, pid, nextPid, entryAddress, entryLength);
        break;
        
      case LEAF_DELTA:
        addLeafDelta(segment, pid, nextPid, entryAddress, entryLength);
        break;
        
      default:
        System.out.println("UNKNOWN-SEGMENT: " + PageType10.values()[type]);
      }
    }
  }
private void readSegmentIndex ( ReadStream is , Segment10 segment ) throws IOException { int address = segment . length ( ) - BLOCK_SIZE ; TempBuffer tBuf = TempBuffer . create ( ) ; byte [ ] buffer = tBuf . buffer ( ) ; is . position ( address ) ; is . read ( buffer , 0 , BLOCK_SIZE ) ; int tail = BitsUtil . readInt16 ( buffer , FOOTER_OFFSET ) ; if ( tail < TABLE_KEY_SIZE + 8 || tail > BLOCK_SIZE - 8 ) { return ; } int offset = INDEX_OFFSET ; while ( offset < tail ) { int type = buffer [ offset ++ ] & 0xff ; int pid = BitsUtil . readInt ( buffer , offset ) ; offset += 4 ; int nextPid = BitsUtil . readInt ( buffer , offset ) ; offset += 4 ; int entryAddress = BitsUtil . readInt ( buffer , offset ) ; offset += 4 ; int entryLength = BitsUtil . readInt ( buffer , offset ) ; offset += 4 ; if ( pid <= 1 ) { System . out . println ( "INVALID_PID: " + pid ) ; return ; } switch ( PageType10 . values ( ) [ type ] ) { case LEAF : addLeaf ( segment , pid , nextPid , entryAddress , entryLength ) ; break ; case LEAF_DELTA : addLeafDelta ( segment , pid , nextPid , entryAddress , entryLength ) ; break ; default : System . out . println ( "UNKNOWN-SEGMENT: " + PageType10 . values ( ) [ type ] ) ; } } }
Read page index from a segment.