public static int deflate(byte[] previous,int previousLength,byte[] current,int currentLength,byte[] result){
  if (previous == null) {
    System.arraycopy(current,0,result,0,currentLength);
    return currentLength;
  }
  int length=0;
  int start1=0;
  int start2=0;
  while (start1 < previousLength && start2 < currentLength) {
    int end1=start1;
    int end2=start2;
    while (end1 <= previousLength && end2 <= currentLength) {
      byte c1=(end1 < previousLength ? previous[end1] : (byte)'\t');
      byte c2=(end2 < currentLength ? current[end2] : (byte)'\t');
      if (c1 == c2) {
        if (c1 == '\t') {
          result[length++]='&';
          break;
        }
 else {
          end1++;
          end2++;
        }
      }
 else {
        while (end1 < previousLength && previous[end1] != '\t') {
          end1++;
        }
        while (end2 < currentLength && current[end2] != '\t') {
          end2++;
        }
        for (int i=start2; i < end2; i++)         result[length++]=current[i];
        break;
      }
    }
    start1=end1 + 1;
    start2=end2 + 1;
    if (start2 < currentLength)     result[length++]='\t';
  }
  return length;
}

public static int deflate ( byte [ ] previous , int previousLength , byte [ ] current , int currentLength , byte [ ] result ) { if ( previous == null ) { System . arraycopy ( current , 0 , result , 0 , currentLength ) ; return currentLength ; } int length = 0 ; int start1 = 0 ; int start2 = 0 ; while ( start1 < previousLength && start2 < currentLength ) { int end1 = start1 ; int end2 = start2 ; while ( end1 <= previousLength && end2 <= currentLength ) { byte c1 = ( end1 < previousLength ? previous [ end1 ] : ( byte ) '\t' ) ; byte c2 = ( end2 < currentLength ? current [ end2 ] : ( byte ) '\t' ) ; if ( c1 == c2 ) { if ( c1 == '\t' ) { result [ length ++ ] = '&' ; break ; } else { end1 ++ ; end2 ++ ; } } else { while ( end1 < previousLength && previous [ end1 ] != '\t' ) { end1 ++ ; } while ( end2 < currentLength && current [ end2 ] != '\t' ) { end2 ++ ; } for ( int i = start2 ; i < end2 ; i ++ ) result [ length ++ ] = current [ i ] ; break ; } } start1 = end1 + 1 ; start2 = end2 + 1 ; if ( start2 < currentLength ) result [ length ++ ] = '\t' ; } return length ; }
deflate current sam line by replacing all fields that equalovershorterofboth previous line by an ampersand
