public static int compareTo(ByteBuff buf1, int o1, int len1, ByteBuff buf2, int o2, int len2) {
    if (buf1.hasArray() && buf2.hasArray()) {
      return Bytes.compareTo(buf1.array(), buf1.arrayOffset() + o1, len1, buf2.array(),
        buf2.arrayOffset() + o2, len2);
    }
    int end1 = o1 + len1;
    int end2 = o2 + len2;
    for (int i = o1, j = o2; i < end1 && j < end2; i++, j++) {
      int a = buf1.get(i) & 0xFF;
      int b = buf2.get(j) & 0xFF;
      if (a != b) {
        return a - b;
      }
    }
    return len1 - len2;
  }
Compares two ByteBuffs
@param buf1 the first ByteBuff
@param o1   the offset in the first ByteBuff from where the compare has to happen
@param len1 the length in the first ByteBuff upto which the compare has to happen
@param buf2 the second ByteBuff
@param o2   the offset in the second ByteBuff from where the compare has to happen
@param len2 the length in the second ByteBuff upto which the compare has to happen
@return Positive if buf1 is bigger than buf2, 0 if they are equal, and negative if buf1 is
        smaller than buf2.
hbase-common/src/main/java/org/apache/hadoop/hbase/nio/ByteBuff.java