public synchronized void markUsed(long pos,int length){
  int start=(int)(pos / blockSize);
  int required=getBlockCount(length);
  BlockRange found=null;
  int i=0;
  for (  BlockRange pr : freeSpaceList) {
    if (start >= pr.start && start < (pr.start + pr.length)) {
      found=pr;
      break;
    }
    i++;
  }
  if (found == null) {
    throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"Cannot find spot to mark as used in free list");
  }
  if (start + required > found.start + found.length) {
    throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"Runs over edge of free space");
  }
  if (found.start == start) {
    found.start+=required;
    found.length-=required;
    if (found.length == 0) {
      freeSpaceList.remove(i);
    }
  }
 else   if (found.start + found.length == start + required) {
    found.length-=required;
  }
 else {
    int length1=start - found.start;
    int start2=start + required;
    int length2=found.start + found.length - start - required;
    found.length=length1;
    BlockRange newRange=new BlockRange(start2,length2);
    freeSpaceList.add(i + 1,newRange);
  }
}

public synchronized void markUsed ( long pos , int length ) { int start = ( int ) ( pos / blockSize ) ; int required = getBlockCount ( length ) ; BlockRange found = null ; int i = 0 ; for ( BlockRange pr : freeSpaceList ) { if ( start >= pr . start && start < ( pr . start + pr . length ) ) { found = pr ; break ; } i ++ ; } if ( found == null ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Cannot find spot to mark as used in free list" ) ; } if ( start + required > found . start + found . length ) { throw DataUtils . newIllegalStateException ( DataUtils . ERROR_INTERNAL , "Runs over edge of free space" ) ; } if ( found . start == start ) { found . start += required ; found . length -= required ; if ( found . length == 0 ) { freeSpaceList . remove ( i ) ; } } else if ( found . start + found . length == start + required ) { found . length -= required ; } else { int length1 = start - found . start ; int start2 = start + required ; int length2 = found . start + found . length - start - required ; found . length = length1 ; BlockRange newRange = new BlockRange ( start2 , length2 ) ; freeSpaceList . add ( i + 1 , newRange ) ; } }
mark the space as in use .
