public static boolean arePartsEqual(ByteBuffer buffer, int offsetLeft, int lengthLeft,
                                        int offsetRight, int lengthRight) {
        if (lengthLeft != lengthRight) {
            return false;
        }

        if (buffer.hasArray()) {
            return 0 == Bytes.compareTo(buffer.array(), buffer.arrayOffset() + offsetLeft, lengthLeft,
                    buffer.array(), buffer.arrayOffset() + offsetRight, lengthRight);
        }

        for (int i = 0; i < lengthRight; ++i) {
            if (buffer.get(offsetLeft + i) != buffer.get(offsetRight + i)) {
                return false;
            }
        }
        return true;
    }
Check whether two parts in the same buffer are equal.

@param buffer      In which buffer there are parts
@param offsetLeft  Beginning of first part.
@param lengthLeft  Length of the first part.
@param offsetRight Beginning of the second part.
@param lengthRight Length of the second part.
@return True if equal
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java