public synchronized void free(long pos,int length){
  int start=(int)(pos / blockSize);
  int required=getBlockCount(length);
  BlockRange found=null;
  int i=0;
  for (  BlockRange pr : freeSpaceList) {
    if (pr.start > start) {
      found=pr;
      break;
    }
    i++;
  }
  if (found == null) {
    throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"Cannot find spot to mark as unused in free list");
  }
  if (start + required == found.start) {
    found.start=start;
    found.length+=required;
    if (i > 0) {
      BlockRange previous=freeSpaceList.get(i - 1);
      if (previous.start + previous.length == found.start) {
        previous.length+=found.length;
        freeSpaceList.remove(i);
      }
    }
    return;
  }
  if (i > 0) {
    BlockRange previous=freeSpaceList.get(i - 1);
    if (previous.start + previous.length == start) {
      previous.length+=required;
      return;
    }
  }
  BlockRange newRange=new BlockRange(start,required);
  freeSpaceList.add(i,newRange);
}

public synchronized void free ( long pos , int length ) { int start = ( int ) ( pos / blockSize ) ; int required = getBlockCount ( length ) ; BlockRange found = null ; int i = 0 ; for ( BlockRange pr : freeSpaceList ) { if ( pr . start > start ) { found = pr ; break ; } i ++ ; } if ( found == null ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Cannot find spot to mark as unused in free list" ) ; } if ( start + required == found . start ) { found . start = start ; found . length += required ; if ( i > 0 ) { BlockRange previous = freeSpaceList . get ( i - 1 ) ; if ( previous . start + previous . length == found . start ) { previous . length += found . length ; freeSpaceList . remove ( i ) ; } } return ; } if ( i > 0 ) { BlockRange previous = freeSpaceList . get ( i - 1 ) ; if ( previous . start + previous . length == start ) { previous . length += required ; return ; } } BlockRange newRange = new BlockRange ( start , required ) ; freeSpaceList . add ( i , newRange ) ; }
mark the space as free .
