ByteUtil { public static boolean matchesStart(byte[] source, byte[] prefix) { if (source == null) return false; if (source.length < prefix.length) return false; for (int i=0; i<prefix.length; i++) { if (prefix[i] != source[i]) return false; } return true; } private  ByteUtil(); static boolean matchesStart(byte[] source, byte[] prefix); static boolean matches(byte[] source, byte[] prefix, int offset);  }
@Test public void matchesStart() { byte[] prefix = new byte[] { 1, 2, 3 }; byte[] candidate1 = new byte[] { 1, 2, 3, 4, 5}; byte[] candidate2 = new byte[] { 2, 3, 4, 5}; byte[] candidate3 = new byte[] { 1, 2}; byte[] candidate4 = new byte[] { }; byte[] candidate5 = new byte[] { 1, 2, 3, 4, 5, 1, 2, 3}; assertTrue(ByteUtil.matchesStart(candidate1, prefix)); assertFalse(ByteUtil.matchesStart(candidate2, prefix)); assertFalse(ByteUtil.matchesStart(candidate3, prefix)); assertFalse(ByteUtil.matchesStart(candidate4, prefix)); assertTrue(ByteUtil.matchesStart(candidate5, prefix)); }