private Diff generateDiff(final char[] revA,final char[] revB) throws UnsupportedEncodingException {
  blockCount=0;
  queueA=new ArrayList<DiffBlock>();
  queueB=new ArrayList<DiffBlock>();
  revABlocked=new boolean[revA.length];
  revBBlocked=new boolean[revB.length];
  int revAStartIndex=0, revAEndIndex=revA.length - 1;
  int revBStartIndex=0, revBEndIndex=revB.length - 1;
  while (revAStartIndex <= revAEndIndex && revBStartIndex <= revBEndIndex && revA[revAStartIndex] == revB[revBStartIndex]) {
    revABlocked[revAStartIndex]=true;
    revBBlocked[revBStartIndex]=true;
    revAStartIndex++;
    revBStartIndex++;
  }
  if (revAStartIndex != 0) {
    queueA.add(new DiffBlock(this.blockCount,0,revAStartIndex,0,revBStartIndex,true));
    queueB.add(new DiffBlock(this.blockCount,0,revAStartIndex,0,revBStartIndex,false));
    this.blockCount++;
  }
  while (revAStartIndex < revAEndIndex && revBStartIndex < revBEndIndex && revA[revAEndIndex] == revB[revBEndIndex]) {
    revABlocked[revAEndIndex]=true;
    revBBlocked[revBEndIndex]=true;
    revAEndIndex--;
    revBEndIndex--;
  }
  if (revAEndIndex + 1 != revA.length) {
    queueA.add(new DiffBlock(this.blockCount,revAEndIndex + 1,revA.length,revBEndIndex + 1,revB.length,true));
    queueB.add(new DiffBlock(this.blockCount,revAEndIndex + 1,revA.length,revBEndIndex + 1,revB.length,false));
    this.blockCount++;
  }
  scan(revA,revAStartIndex,revAEndIndex);
  ArrayList<Integer> list;
  char c;
  int i=revBStartIndex;
  while (i < revBEndIndex) {
    c=revB[i];
    list=positions.get(c);
    if (list != null && findLongestMatch(revA,list,revB,i)) {
      i+=longestMatch_size;
    }
 else {
      i++;
    }
  }
  int j;
  for (i=revAStartIndex; i <= revAEndIndex; i++) {
    if (!revABlocked[i]) {
      j=i;
      while (i + 1 <= revAEndIndex && !revABlocked[++i]) {
        ;
      }
      if (i + 1 > revAEndIndex) {
        i++;
      }
      queueA.add(new DiffBlock(-1,j,i,-1,-1,true));
    }
  }
  for (i=revBStartIndex; i <= revBEndIndex; i++) {
    if (!revBBlocked[i]) {
      j=i;
      while (i + 1 <= revBEndIndex && !revBBlocked[++i]) {
        ;
      }
      if (i + 1 > revBEndIndex) {
        i++;
      }
      queueB.add(new DiffBlock(-1,-1,-1,j,i,false));
    }
  }
  Collections.sort(queueA);
  Collections.sort(queueB);
  return blocks.manage(revA,revB,queueA,queueB);
}

private Diff generateDiff ( final char [ ] revA , final char [ ] revB ) throws UnsupportedEncodingException { blockCount = 0 ; queueA = new ArrayList < DiffBlock > ( ) ; queueB = new ArrayList < DiffBlock > ( ) ; revABlocked = new boolean [ revA . length ] ; revBBlocked = new boolean [ revB . length ] ; int revAStartIndex = 0 , revAEndIndex = revA . length - 1 ; int revBStartIndex = 0 , revBEndIndex = revB . length - 1 ; while ( revAStartIndex <= revAEndIndex && revBStartIndex <= revBEndIndex && revA [ revAStartIndex ] == revB [ revBStartIndex ] ) { revABlocked [ revAStartIndex ] = true ; revBBlocked [ revBStartIndex ] = true ; revAStartIndex ++ ; revBStartIndex ++ ; } if ( revAStartIndex != 0 ) { queueA . add ( new DiffBlock ( this . blockCount , 0 , revAStartIndex , 0 , revBStartIndex , true ) ) ; queueB . add ( new DiffBlock ( this . blockCount , 0 , revAStartIndex , 0 , revBStartIndex , false ) ) ; this . blockCount ++ ; } while ( revAStartIndex < revAEndIndex && revBStartIndex < revBEndIndex && revA [ revAEndIndex ] == revB [ revBEndIndex ] ) { revABlocked [ revAEndIndex ] = true ; revBBlocked [ revBEndIndex ] = true ; revAEndIndex -- ; revBEndIndex -- ; } if ( revAEndIndex + 1 != revA . length ) { queueA . add ( new DiffBlock ( this . blockCount , revAEndIndex + 1 , revA . length , revBEndIndex + 1 , revB . length , true ) ) ; queueB . add ( new DiffBlock ( this . blockCount , revAEndIndex + 1 , revA . length , revBEndIndex + 1 , revB . length , false ) ) ; this . blockCount ++ ; } scan ( revA , revAStartIndex , revAEndIndex ) ; ArrayList < Integer > list ; char c ; int i = revBStartIndex ; while ( i < revBEndIndex ) { c = revB [ i ] ; list = positions . get ( c ) ; if ( list != null && findLongestMatch ( revA , list , revB , i ) ) { i += longestMatch_size ; } else { i ++ ; } } int j ; for ( i = revAStartIndex ; i <= revAEndIndex ; i ++ ) { if ( ! revABlocked [ i ] ) { j = i ; while ( i + 1 <= revAEndIndex && ! revABlocked [ ++ i ] ) { ; } if ( i + 1 > revAEndIndex ) { i ++ ; } queueA . add ( new DiffBlock ( - 1 , j , i , - 1 , - 1 , true ) ) ; } } for ( i = revBStartIndex ; i <= revBEndIndex ; i ++ ) { if ( ! revBBlocked [ i ] ) { j = i ; while ( i + 1 <= revBEndIndex && ! revBBlocked [ ++ i ] ) { ; } if ( i + 1 > revBEndIndex ) { i ++ ; } queueB . add ( new DiffBlock ( - 1 , - 1 , - 1 , j , i , false ) ) ; } } Collections . sort ( queueA ) ; Collections . sort ( queueB ) ; return blocks . manage ( revA , revB , queueA , queueB ) ; }
generates a diff by using the commonlongestsubstring search .
