@Override
            public int compareTo(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2) {
                int end1 = o1 + l1;
                int end2 = o2 + l2;
                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 l1 - l2;
            }
Utility functions for working with byte buffers, such as reading/writing variable-length long
numbers.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java