@Override
    public int indexOf(int fromIndex, int toIndex, byte value) {
        if (fromIndex <= toIndex) {
            return ByteBufUtil.firstIndexOf(this, fromIndex, toIndex, value);
        }
        return ByteBufUtil.lastIndexOf(this, fromIndex, toIndex, value);
    }
@Test
    public void testIndexOf() {
        buffer.clear();
        // Ensure the buffer is completely zero'ed.
        buffer.setZero(0, buffer.capacity());

        buffer.writeByte((byte) 1);
        buffer.writeByte((byte) 2);
        buffer.writeByte((byte) 3);
        buffer.writeByte((byte) 2);
        buffer.writeByte((byte) 1);

        assertEquals(-1, buffer.indexOf(1, 4, (byte) 1));
        assertEquals(-1, buffer.indexOf(4, 1, (byte) 1));
        assertEquals(1, buffer.indexOf(1, 4, (byte) 2));
        assertEquals(3, buffer.indexOf(4, 1, (byte) 2));

        try {
            buffer.indexOf(0, buffer.capacity() + 1, (byte) 0);
            fail();
        } catch (IndexOutOfBoundsException expected) {
            // expected
        }

        try {
            buffer.indexOf(buffer.capacity(), -1, (byte) 0);
            fail();
        } catch (IndexOutOfBoundsException expected) {
            // expected
        }

        assertEquals(4, buffer.indexOf(buffer.capacity() + 1, 0, (byte) 1));
        assertEquals(0, buffer.indexOf(-1, buffer.capacity(), (byte) 1));
    }