public int compareTo(byte[] buffer1,int offset1,int length1,byte[] buffer2,int offset2,int length2){
  if (buffer1 == buffer2 && offset1 == offset2 && length1 == length2) {
    return 0;
  }
  int minLength=Math.min(length1,length2);
  int minWords=minLength / SIZEOF_LONG;
  int offset1Adj=offset1 + BYTE_ARRAY_BASE_OFFSET;
  int offset2Adj=offset2 + BYTE_ARRAY_BASE_OFFSET;
  for (int i=0; i < minWords * SIZEOF_LONG; i+=SIZEOF_LONG) {
    long lw=THEUNSAFE.getLong(buffer1,offset1Adj + (long)i);
    long rw=THEUNSAFE.getLong(buffer2,offset2Adj + (long)i);
    long diff=lw ^ rw;
    if (diff != 0) {
      if (!LITTLEENDIAN) {
        return lessThanUnsigned(lw,rw) ? -1 : 1;
      }
      int n=0;
      int y;
      int x=(int)diff;
      if (x == 0) {
        x=(int)(diff >>> 32);
        n=32;
      }
      y=x << 16;
      if (y == 0) {
        n+=16;
      }
 else {
        x=y;
      }
      y=x << 8;
      if (y == 0) {
        n+=8;
      }
      return (int)(((lw >>> n) & 0xFFL) - ((rw >>> n) & 0xFFL));
    }
  }
  for (int i=minWords * SIZEOF_LONG; i < minLength; i++) {
    int a=(buffer1[offset1 + i] & 0xff);
    int b=(buffer2[offset2 + i] & 0xff);
    if (a != b) {
      return a - b;
    }
  }
  return length1 - length2;
}

public int compareTo ( byte [ ] buffer1 , int offset1 , int length1 , byte [ ] buffer2 , int offset2 , int length2 ) { if ( buffer1 == buffer2 && offset1 == offset2 && length1 == length2 ) { return 0 ; } int minLength = Math . min ( length1 , length2 ) ; int minWords = minLength / SIZEOF_LONG ; int offset1Adj = offset1 + BYTE_ARRAY_BASE_OFFSET ; int offset2Adj = offset2 + BYTE_ARRAY_BASE_OFFSET ; for ( int i = 0 ; i < minWords * SIZEOF_LONG ; i += SIZEOF_LONG ) { long lw = THEUNSAFE . getLong ( buffer1 , offset1Adj + ( long ) i ) ; long rw = THEUNSAFE . getLong ( buffer2 , offset2Adj + ( long ) i ) ; long diff = lw ^ rw ; if ( diff != 0 ) { if ( ! LITTLEENDIAN ) { return lessThanUnsigned ( lw , rw ) ? - 1 : 1 ; } int n = 0 ; int y ; int x = ( int ) diff ; if ( x == 0 ) { x = ( int ) ( diff > > > 32 ) ; n = 32 ; } y = x << 16 ; if ( y == 0 ) { n += 16 ; } else { x = y ; } y = x << 8 ; if ( y == 0 ) { n += 8 ; } return ( int ) ( ( ( lw > > > n ) & 0xFFL ) - ( ( rw > > > n ) & 0xFFL ) ) ; } } for ( int i = minWords * SIZEOF_LONG ; i < minLength ; i ++ ) { int a = ( buffer1 [ offset1 + i ] & 0xff ) ; int b = ( buffer2 [ offset2 + i ] & 0xff ) ; if ( a != b ) { return a - b ; } } return length1 - length2 ; }
lexicographically compare two arrays .
