@Test public void startsWith() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(TEST_BYTES1.length); buffer.add(TEST_BYTES1); Assert.assertEquals(true, buffer.startsWith(TEST_H)); Assert.assertEquals(true, buffer.startsWith(TEST_HELLO)); Assert.assertEquals(false, buffer.startsWith(TEST_WORLD)); Assert.assertEquals(false, buffer.startsWith(TEST_W)); buffer.clear(); buffer.add(TEST_WORLD); Assert.assertEquals(false, buffer.startsWith(TEST_H)); Assert.assertEquals(false, buffer.startsWith(TEST_HELLO)); Assert.assertEquals(true, buffer.startsWith(TEST_WORLD)); Assert.assertEquals(true, buffer.startsWith(TEST_W)); buffer.clear(); buffer.add(TEST_HELLO); Assert.assertEquals(true, buffer.startsWith(TEST_H)); Assert.assertEquals(true, buffer.startsWith(TEST_HELLO)); Assert.assertEquals(false, buffer.startsWith(TEST_BYTES1)); }
public boolean startsWith(byte[] prefix) { if ((prefix.length == 0) || (prefix.length > size())) { return false; } boolean match = true; int i = 0; int j = this.currentReadPosition; while (match && (i < prefix.length)) { if (this.buffer[j] != prefix[i]) { match = false; } i++; j = (j + 1) % this.buffer.length; } return match; }
ByteBuffer { public boolean startsWith(byte[] prefix) { if ((prefix.length == 0) || (prefix.length > size())) { return false; } boolean match = true; int i = 0; int j = this.currentReadPosition; while (match && (i < prefix.length)) { if (this.buffer[j] != prefix[i]) { match = false; } i++; j = (j + 1) % this.buffer.length; } return match; } }
ByteBuffer { public boolean startsWith(byte[] prefix) { if ((prefix.length == 0) || (prefix.length > size())) { return false; } boolean match = true; int i = 0; int j = this.currentReadPosition; while (match && (i < prefix.length)) { if (this.buffer[j] != prefix[i]) { match = false; } i++; j = (j + 1) % this.buffer.length; } return match; } ByteBuffer();  ByteBuffer(int capacity);  ByteBuffer(byte[] bytes);  ByteBuffer(byte[] bytes, int capacity);  ByteBuffer(byte[] bytes, int offset, int length);  ByteBuffer(byte[] bytes, int offset, int length, int capacity);  ByteBuffer(String string0);  ByteBuffer(String string0, int capacity); }
ByteBuffer { public boolean startsWith(byte[] prefix) { if ((prefix.length == 0) || (prefix.length > size())) { return false; } boolean match = true; int i = 0; int j = this.currentReadPosition; while (match && (i < prefix.length)) { if (this.buffer[j] != prefix[i]) { match = false; } i++; j = (j + 1) % this.buffer.length; } return match; } ByteBuffer();  ByteBuffer(int capacity);  ByteBuffer(byte[] bytes);  ByteBuffer(byte[] bytes, int capacity);  ByteBuffer(byte[] bytes, int offset, int length);  ByteBuffer(byte[] bytes, int offset, int length, int capacity);  ByteBuffer(String string0);  ByteBuffer(String string0, int capacity); int size(); int capacity(); int free(); boolean isFree(int count); boolean isEmpty(); boolean isFull(); void clear(); void add(byte b); void add(byte[] bytes); void add(byte[] bytes, int offset, int length); void delete(int count); byte remove(); byte[] remove(int count); int occurrences(byte b); int occurrences(byte[] bytes); ByteBuffer copy(); ByteBuffer copy(int offset, int length); ByteBuffer copy(int offset, int length, int capacity); byte get(int index); byte[] toArray(); byte[] toArray(int offset, int length); byte[] toArray(int offset, int length, int capacity); void toArray(int offset, int length, byte[] targetBuffer, int targetOffset); boolean startsWith(byte[] prefix); boolean endsWith(byte[] prefix); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int offset); @Override int hashCode(); @Override boolean equals(Object obj); boolean equals(byte[] bytes); @Override String toString(); String toHexString(); String toHexString(int offset, int length); }
ByteBuffer { public boolean startsWith(byte[] prefix) { if ((prefix.length == 0) || (prefix.length > size())) { return false; } boolean match = true; int i = 0; int j = this.currentReadPosition; while (match && (i < prefix.length)) { if (this.buffer[j] != prefix[i]) { match = false; } i++; j = (j + 1) % this.buffer.length; } return match; } ByteBuffer();  ByteBuffer(int capacity);  ByteBuffer(byte[] bytes);  ByteBuffer(byte[] bytes, int capacity);  ByteBuffer(byte[] bytes, int offset, int length);  ByteBuffer(byte[] bytes, int offset, int length, int capacity);  ByteBuffer(String string0);  ByteBuffer(String string0, int capacity); int size(); int capacity(); int free(); boolean isFree(int count); boolean isEmpty(); boolean isFull(); void clear(); void add(byte b); void add(byte[] bytes); void add(byte[] bytes, int offset, int length); void delete(int count); byte remove(); byte[] remove(int count); int occurrences(byte b); int occurrences(byte[] bytes); ByteBuffer copy(); ByteBuffer copy(int offset, int length); ByteBuffer copy(int offset, int length, int capacity); byte get(int index); byte[] toArray(); byte[] toArray(int offset, int length); byte[] toArray(int offset, int length, int capacity); void toArray(int offset, int length, byte[] targetBuffer, int targetOffset); boolean startsWith(byte[] prefix); boolean endsWith(byte[] prefix); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int offset); @Override int hashCode(); @Override boolean equals(Object obj); boolean equals(byte[] bytes); @Override String toString(); String toHexString(); String toHexString(int offset, int length);  }