public static boolean equalIncreasingByteBuffer(int start, int len, ByteBuffer buf) {
    if (buf == null) {
      return false;
    }
    buf.rewind();
    if (buf.remaining() != len) {
      return false;
    }
    for (int k = 0; k < len; k++) {
      if (buf.get() != (byte) (start + k)) {
        return false;
      }
    }
    return true;
  }
@Test
  public void equalIncreasingByteBuffer() {
    class TestCase {
      boolean mExpected;
      ByteBuffer mBuffer;
      int mLength;
      int mStart;

      public TestCase(boolean expected, ByteBuffer buffer, int length, int start) {
        mExpected = expected;
        mBuffer = buffer;
        mLength = length;
        mStart = start;
      }
    }

    ArrayList<TestCase> testCases = new ArrayList<>();
    testCases.add(new TestCase(false, null, 0, 0));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {}), 0, 0));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {1}), 0, 0));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {}), 0, 3));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {1}), 0, 3));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {0}), 1, 0));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {1}), 1, 0));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {0, 1, 2}), 3, 0));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {0, 1, 2, (byte) 0xFF}), 3, 0));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {1, 2, 3}), 3, 0));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {3}), 1, 3));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {2}), 1, 3));
    testCases.add(new TestCase(true, ByteBuffer.wrap(new byte[] {3, 4, 5}), 3, 3));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {3, 4, 5, (byte) 0xFF}), 3, 3));
    testCases.add(new TestCase(false, ByteBuffer.wrap(new byte[] {2, 3, 4}), 3, 3));

    for (TestCase testCase : testCases) {
      boolean result = BufferUtils.equalIncreasingByteBuffer(testCase.mStart, testCase.mLength,
          testCase.mBuffer);
      assertEquals(testCase.mExpected, result);
    }
  }