ByteBuffer { public int occurrences(byte b) { byte[] bytes = { b }; return occurrences(bytes); } 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);  }
@Test public void occurrences() throws BufferException { ByteBuffer buffer = new ByteBuffer(TEST_BYTES1); Assert.assertEquals(-1, buffer.occurrences(new byte[0])); Assert.assertEquals(3, buffer.occurrences(TEST_L)); Assert.assertEquals(1, buffer.occurrences(TEST_LL)); Assert.assertEquals(1, buffer.occurrences(TEST_H)); byte[] tmp = {'A'}; Assert.assertEquals(0, buffer.occurrences(tmp)); }
@Test public void occurrencesWithByte() throws BufferException { ByteBuffer buffer = new ByteBuffer(TEST_BYTES1); Assert.assertEquals(3, buffer.occurrences((byte)'L')); Assert.assertEquals(1, buffer.occurrences((byte)'H')); Assert.assertEquals(0, buffer.occurrences((byte)'A')); }
@Test public void occurrencesWithOverlap() throws BufferException { ByteBuffer buffer = new ByteBuffer(TEST_BYTES2); Assert.assertEquals(-1, buffer.occurrences(new byte[0])); Assert.assertEquals(1, buffer.occurrences(TEST_C)); Assert.assertEquals(4, buffer.occurrences(TEST_AA)); Assert.assertEquals(2, buffer.occurrences(TEST_AB)); Assert.assertEquals(3, buffer.occurrences(TEST_BB)); }