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