@Test public void testIndexOf() throws Exception { final byte COLON = (byte) ':'; final byte COMMA = (byte) ','; final byte[] bytes = "name1: value1; name2: value2".getBytes(StandardCharsets.US_ASCII); final int index1 = 5; final int index2 = 20; final ByteArrayBuffer buffer = new ByteArrayBuffer(16); buffer.append(bytes, 0, bytes.length); Assert.assertEquals(index1, buffer.indexOf(COLON)); Assert.assertEquals(-1, buffer.indexOf(COMMA)); Assert.assertEquals(index1, buffer.indexOf(COLON, -1, 11)); Assert.assertEquals(index1, buffer.indexOf(COLON, 0, 1000)); Assert.assertEquals(-1, buffer.indexOf(COLON, 2, 1)); Assert.assertEquals(index2, buffer.indexOf(COLON, index1 + 1, buffer.length())); }
public int indexOf(final byte b, final int from, final int to) { int beginIndex = from; if (beginIndex < 0) { beginIndex = 0; } int endIndex = to; if (endIndex > this.len) { endIndex = this.len; } if (beginIndex > endIndex) { return -1; } for (int i = beginIndex; i < endIndex; i++) { if (this.array[i] == b) { return i; } } return -1; }
ByteArrayBuffer implements Serializable { public int indexOf(final byte b, final int from, final int to) { int beginIndex = from; if (beginIndex < 0) { beginIndex = 0; } int endIndex = to; if (endIndex > this.len) { endIndex = this.len; } if (beginIndex > endIndex) { return -1; } for (int i = beginIndex; i < endIndex; i++) { if (this.array[i] == b) { return i; } } return -1; } }
ByteArrayBuffer implements Serializable { public int indexOf(final byte b, final int from, final int to) { int beginIndex = from; if (beginIndex < 0) { beginIndex = 0; } int endIndex = to; if (endIndex > this.len) { endIndex = this.len; } if (beginIndex > endIndex) { return -1; } for (int i = beginIndex; i < endIndex; i++) { if (this.array[i] == b) { return i; } } return -1; } ByteArrayBuffer(final int capacity); }
ByteArrayBuffer implements Serializable { public int indexOf(final byte b, final int from, final int to) { int beginIndex = from; if (beginIndex < 0) { beginIndex = 0; } int endIndex = to; if (endIndex > this.len) { endIndex = this.len; } if (beginIndex > endIndex) { return -1; } for (int i = beginIndex; i < endIndex; i++) { if (this.array[i] == b) { return i; } } return -1; } ByteArrayBuffer(final int capacity); void append(final byte[] b, final int off, final int len); void append(final int b); void append(final char[] b, final int off, final int len); void append(final CharArrayBuffer b, final int off, final int len); void append(final ByteBuffer buffer); void clear(); byte[] toByteArray(); int byteAt(final int i); int capacity(); int length(); void ensureCapacity(final int required); byte[] array(); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final byte b, final int from, final int to); int indexOf(final byte b); }
ByteArrayBuffer implements Serializable { public int indexOf(final byte b, final int from, final int to) { int beginIndex = from; if (beginIndex < 0) { beginIndex = 0; } int endIndex = to; if (endIndex > this.len) { endIndex = this.len; } if (beginIndex > endIndex) { return -1; } for (int i = beginIndex; i < endIndex; i++) { if (this.array[i] == b) { return i; } } return -1; } ByteArrayBuffer(final int capacity); void append(final byte[] b, final int off, final int len); void append(final int b); void append(final char[] b, final int off, final int len); void append(final CharArrayBuffer b, final int off, final int len); void append(final ByteBuffer buffer); void clear(); byte[] toByteArray(); int byteAt(final int i); int capacity(); int length(); void ensureCapacity(final int required); byte[] array(); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final byte b, final int from, final int to); int indexOf(final byte b);  }