public RandomAccessData increment() throws IOException {
    RandomAccessData copy = copy();
    for (int i = copy.size - 1; i >= 0; --i) {
      if (copy.buffer[i] != UnsignedBytes.MAX_VALUE) {
        copy.buffer[i] = UnsignedBytes.checkedCast(UnsignedBytes.toInt(copy.buffer[i]) + 1L);
        return copy;
      }
    }
    return POSITIVE_INFINITY;
  }
@Test
  public void testIncrement() throws Exception {
    assertEquals(
        new RandomAccessData(new byte[] {0x00, 0x01}),
        new RandomAccessData(new byte[] {0x00, 0x00}).increment());
    assertEquals(
        new RandomAccessData(new byte[] {0x01, UnsignedBytes.MAX_VALUE}),
        new RandomAccessData(new byte[] {0x00, UnsignedBytes.MAX_VALUE}).increment());

    // Test for positive infinity
    assertSame(RandomAccessData.POSITIVE_INFINITY, new RandomAccessData(new byte[0]).increment());
    assertSame(
        RandomAccessData.POSITIVE_INFINITY,
        new RandomAccessData(new byte[] {UnsignedBytes.MAX_VALUE}).increment());
    assertSame(RandomAccessData.POSITIVE_INFINITY, RandomAccessData.POSITIVE_INFINITY.increment());
  }