@Override
      public int findCommonPrefix(ByteBuffer left, int leftOffset, int leftLength, byte[] right,
        int rightOffset, int rightLength) {
        int length = Math.min(leftLength, rightLength);
        int result = 0;

        while (
          result < length
            && ByteBufferUtils.toByte(left, leftOffset + result) == right[rightOffset + result]
        ) {
          result++;
        }

        return result;
      }
Utility functions for working with byte buffers, such as reading/writing variable-length long
numbers.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java