UTF8ByteArrayUtils { public static int findByte(byte [] utf, int start, int end, byte b) { for(int i=start; i<end; i++) { if (utf[i]==b) { return i; } } return -1; }  static int findByte(byte [] utf, int start, int end, byte b); static int findBytes(byte [] utf, int start, int end, byte[] b); static int findNthByte(byte [] utf, int start, int length, byte b, int n); static int findNthByte(byte [] utf, byte b, int n);  }
@Test public void testFindByte() { byte[] data = "Hello, world!".getBytes(); assertEquals("Character 'a' does not exist in string", -1, UTF8ByteArrayUtils.findByte(data, 0, data.length, (byte) 'a')); assertEquals("Did not find first occurrence of character 'o'", 4, UTF8ByteArrayUtils.findByte(data, 0, data.length, (byte) 'o')); }