@Test public void testIndexOf() { String s = "123456\r\n9\r\n\r\n"; byte[] bytes = s.getBytes(); int idx = ByteUtil.indexOf(bytes, (byte) '9'); Assert.assertEquals(8, idx); idx = ByteUtil.indexOf(bytes, new byte[] { '\r', '\n', '\r', '\n' }); Assert.assertEquals(9, idx); idx = ByteUtil.indexOf(bytes, new byte[] { '\t', '\n' }); Assert.assertEquals(-1, idx); System.out.println(String.format("[CRAFT-ATOM-UTIL] (^_^) <%s> Case -> test indexof. ", CaseCounter.incr(3))); }
public static int indexOf(final byte[] source, final byte[] target) { if (source == null || target == null) { return -1; } if (target.length == 1) { return indexOf(source, target[0]); } else { return indexOf(source, 0, source.length, target, 0, target.length, 0); } }
ByteUtil { public static int indexOf(final byte[] source, final byte[] target) { if (source == null || target == null) { return -1; } if (target.length == 1) { return indexOf(source, target[0]); } else { return indexOf(source, 0, source.length, target, 0, target.length, 0); } } }
ByteUtil { public static int indexOf(final byte[] source, final byte[] target) { if (source == null || target == null) { return -1; } if (target.length == 1) { return indexOf(source, target[0]); } else { return indexOf(source, 0, source.length, target, 0, target.length, 0); } } private  ByteUtil(); }
ByteUtil { public static int indexOf(final byte[] source, final byte[] target) { if (source == null || target == null) { return -1; } if (target.length == 1) { return indexOf(source, target[0]); } else { return indexOf(source, 0, source.length, target, 0, target.length, 0); } } private  ByteUtil(); static int indexOf(final byte[] source, final byte[] target); static int indexOf(final byte[] source, final byte[] target, int fromIndex); static int indexOf(final byte[] source, final byte[] target, int fromIndex, int endIndex); static int indexOf(byte[] source, byte target); static int indexOf(byte[] source, byte target, int fromIndex); static int indexOf(byte[] source, byte target, int fromIndex, int endIndex); static byte[] split(byte[] bytes, int start, int end); static byte[] reverse(byte[] src); static String asHex(byte[] bytes); static String asHex(byte[] bytes, String separator); static byte[] intToNetworkByteOrder(int num, int count); static int networkByteOrderToInt(byte[] buf); static int networkByteOrderToInt(byte[] buf, int start, int count); static boolean isEmpty(byte[] bytes); static final short bytes2short(byte[] b); static final short bytes2short(byte[] b, int off); static final byte[] short2bytes(short s); static void short2bytes(short s, byte[] b, int off); static final int bytes2int(byte[] b); static final int bytes2int(byte[] b, int off); static final byte[] int2bytes(int i); static void int2bytes(int i, byte[] b, int off); static final long bytes2long(byte[] b); static final long bytes2long(byte[] b, int off); static final byte[] long2bytes(long l); static void long2bytes(long l, byte[] b, int off); static float bytes2float(byte[] b); static float bytes2float(byte[] b, int off); static final byte[] float2bytes(float f); static void float2bytes(float f, byte[] b, int off); static double bytes2double(byte[] b); static double bytes2double(byte[] b, int off); static final byte[] double2bytes(double d); static void double2bytes(double d, byte[] b, int off); static final int makeIntFromByte2(byte[] b); static final int makeIntFromByte2(byte[] b, int off); static final int makeIntFromByte4(byte[] b); static final int makeIntFromByte4(byte[] b, int off); }
ByteUtil { public static int indexOf(final byte[] source, final byte[] target) { if (source == null || target == null) { return -1; } if (target.length == 1) { return indexOf(source, target[0]); } else { return indexOf(source, 0, source.length, target, 0, target.length, 0); } } private  ByteUtil(); static int indexOf(final byte[] source, final byte[] target); static int indexOf(final byte[] source, final byte[] target, int fromIndex); static int indexOf(final byte[] source, final byte[] target, int fromIndex, int endIndex); static int indexOf(byte[] source, byte target); static int indexOf(byte[] source, byte target, int fromIndex); static int indexOf(byte[] source, byte target, int fromIndex, int endIndex); static byte[] split(byte[] bytes, int start, int end); static byte[] reverse(byte[] src); static String asHex(byte[] bytes); static String asHex(byte[] bytes, String separator); static byte[] intToNetworkByteOrder(int num, int count); static int networkByteOrderToInt(byte[] buf); static int networkByteOrderToInt(byte[] buf, int start, int count); static boolean isEmpty(byte[] bytes); static final short bytes2short(byte[] b); static final short bytes2short(byte[] b, int off); static final byte[] short2bytes(short s); static void short2bytes(short s, byte[] b, int off); static final int bytes2int(byte[] b); static final int bytes2int(byte[] b, int off); static final byte[] int2bytes(int i); static void int2bytes(int i, byte[] b, int off); static final long bytes2long(byte[] b); static final long bytes2long(byte[] b, int off); static final byte[] long2bytes(long l); static void long2bytes(long l, byte[] b, int off); static float bytes2float(byte[] b); static float bytes2float(byte[] b, int off); static final byte[] float2bytes(float f); static void float2bytes(float f, byte[] b, int off); static double bytes2double(byte[] b); static double bytes2double(byte[] b, int off); static final byte[] double2bytes(double d); static void double2bytes(double d, byte[] b, int off); static final int makeIntFromByte2(byte[] b); static final int makeIntFromByte2(byte[] b, int off); static final int makeIntFromByte4(byte[] b); static final int makeIntFromByte4(byte[] b, int off);  }