class BsUtil {

  static int lexicographicalCompare(
      final RandomAccessObject data1,
      final int start1,
      final int length1,
      final RandomAccessObject data2,
      final int start2,
      final int length2)
      throws IOException {
    int bytesLeft = Math.min(length1, length2);

    data1.seek(start1);
    data2.seek(start2);
    while (bytesLeft-- > 0) {
      final int i1 = data1.readUnsignedByte();
      final int i2 = data2.readUnsignedByte();

      if (i1 != i2) {
        return i1 - i2;
      }
    }

    return length1 - length2;
  }

}