private static int compareAs(final ByteBuffer left, int leftPos,
                                 final ByteBuffer right, int rightPos,
                                 int length) {


        int cmp = 0;
        for (int i = 0; i < length && cmp == 0; i++) {
            int iLeft = i + leftPos;
            int iRight = i + rightPos;
            cmp = (i == 0 || (left.get(iLeft) >= 0 == right.get(iRight) >= 0))
                    ? left.get(iLeft) - right.get(iRight)
                    : right.get(iRight) - left.get(iLeft);
        }
//        final int cmp2 = cmp;
//        LAMBDA_LOGGER.info(() -> LogUtil.message("Comparing {}, {}, {}, {} - {}",
//                byteBufferInfo(left), leftPos,
//                byteBufferInfo(right), rightPos,
//                cmp2));
        return cmp;
    }
Credit for this code goes to Dima
(see https://stackoverflow.com/questions/34166809/faster-comparison-of-longs-in-byte-format)
stroom-bytebuffer/src/main/java/stroom/bytebuffer/ByteBufferUtils.java