private Map.Entry<Integer,Integer> addUsageMaps(int numMaps,Integer firstUsedPage) throws IOException {
  JetFormat format=getFormat();
  PageChannel pageChannel=getPageChannel();
  int umapRowLength=format.OFFSET_USAGE_MAP_START + format.USAGE_MAP_TABLE_BYTE_LENGTH;
  int totalUmapSpaceUsage=getRowSpaceUsage(umapRowLength,format) * numMaps;
  int umapPageNumber=PageChannel.INVALID_PAGE_NUMBER;
  int firstRowNum=-1;
  int freeSpace=0;
  Set<Integer> knownPages=new TreeSet<Integer>(Collections.reverseOrder());
  collectUsageMapPages(knownPages);
  ByteBuffer umapBuf=pageChannel.createPageBuffer();
  for (  Integer pageNum : knownPages) {
    pageChannel.readPage(umapBuf,pageNum);
    freeSpace=umapBuf.getShort(format.OFFSET_FREE_SPACE);
    if (freeSpace >= totalUmapSpaceUsage) {
      umapPageNumber=pageNum;
      firstRowNum=getRowsOnDataPage(umapBuf,format);
      break;
    }
  }
  if (umapPageNumber == PageChannel.INVALID_PAGE_NUMBER) {
    umapPageNumber=pageChannel.allocateNewPage();
    freeSpace=format.DATA_PAGE_INITIAL_FREE_SPACE;
    firstRowNum=0;
    umapBuf=createUsageMapDefPage(pageChannel,freeSpace);
  }
  int rowStart=findRowEnd(umapBuf,firstRowNum,format) - umapRowLength;
  int umapRowNum=firstRowNum;
  for (int i=0; i < numMaps; ++i) {
    umapBuf.putShort(getRowStartOffset(umapRowNum,format),(short)rowStart);
    umapBuf.put(rowStart,UsageMap.MAP_TYPE_INLINE);
    if (firstUsedPage != null) {
      umapBuf.putInt(rowStart + 1,firstUsedPage);
      umapBuf.put(rowStart + 5,(byte)1);
    }
    rowStart-=umapRowLength;
    ++umapRowNum;
  }
  freeSpace-=totalUmapSpaceUsage;
  umapBuf.putShort(format.OFFSET_FREE_SPACE,(short)freeSpace);
  umapBuf.putShort(format.OFFSET_NUM_ROWS_ON_DATA_PAGE,(short)umapRowNum);
  pageChannel.writePage(umapBuf,umapPageNumber);
  return new AbstractMap.SimpleImmutableEntry<Integer,Integer>(umapPageNumber,firstRowNum);
}

private Map . Entry < Integer , Integer > addUsageMaps ( int numMaps , Integer firstUsedPage ) throws IOException { JetFormat format = getFormat ( ) ; PageChannel pageChannel = getPageChannel ( ) ; int umapRowLength = format . OFFSET_USAGE_MAP_START + format . USAGE_MAP_TABLE_BYTE_LENGTH ; int totalUmapSpaceUsage = getRowSpaceUsage ( umapRowLength , format ) * numMaps ; int umapPageNumber = PageChannel . INVALID_PAGE_NUMBER ; int firstRowNum = - 1 ; int freeSpace = 0 ; Set < Integer > knownPages = new TreeSet < Integer > ( Collections . reverseOrder ( ) ) ; collectUsageMapPages ( knownPages ) ; ByteBuffer umapBuf = pageChannel . createPageBuffer ( ) ; for ( Integer pageNum : knownPages ) { pageChannel . readPage ( umapBuf , pageNum ) ; freeSpace = umapBuf . getShort ( format . OFFSET_FREE_SPACE ) ; if ( freeSpace >= totalUmapSpaceUsage ) { umapPageNumber = pageNum ; firstRowNum = getRowsOnDataPage ( umapBuf , format ) ; break ; } } if ( umapPageNumber == PageChannel . INVALID_PAGE_NUMBER ) { umapPageNumber = pageChannel . allocateNewPage ( ) ; freeSpace = format . DATA_PAGE_INITIAL_FREE_SPACE ; firstRowNum = 0 ; umapBuf = createUsageMapDefPage ( pageChannel , freeSpace ) ; } int rowStart = findRowEnd ( umapBuf , firstRowNum , format ) - umapRowLength ; int umapRowNum = firstRowNum ; for ( int i = 0 ; i < numMaps ; ++ i ) { umapBuf . putShort ( getRowStartOffset ( umapRowNum , format ) , ( short ) rowStart ) ; umapBuf . put ( rowStart , UsageMap . MAP_TYPE_INLINE ) ; if ( firstUsedPage != null ) { umapBuf . putInt ( rowStart + 1 , firstUsedPage ) ; umapBuf . put ( rowStart + 5 , ( byte ) 1 ) ; } rowStart -= umapRowLength ; ++ umapRowNum ; } freeSpace -= totalUmapSpaceUsage ; umapBuf . putShort ( format . OFFSET_FREE_SPACE , ( short ) freeSpace ) ; umapBuf . putShort ( format . OFFSET_NUM_ROWS_ON_DATA_PAGE , ( short ) umapRowNum ) ; pageChannel . writePage ( umapBuf , umapPageNumber ) ; return new AbstractMap . SimpleImmutableEntry < Integer , Integer > ( umapPageNumber , firstRowNum ) ; }
adds some usage maps for use with this table . this method is expected to be called with a small - ish number of requested usage maps .
