@Override
      public int compareTo(byte[] buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2) {
        long offset2Adj;
        Object refObj2 = null;
        if (buf2.isDirect()) {
          offset2Adj = o2 + UnsafeAccess.directBufferAddress(buf2);
        } else {
          offset2Adj = o2 + buf2.arrayOffset() + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET;
          refObj2 = buf2.array();
        }
        return compareToUnsafe(buf1, o1 + UnsafeAccess.BYTE_ARRAY_BASE_OFFSET, l1, refObj2,
          offset2Adj, l2);
      }
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