thijs
06/28/2016, 11:53 AMpublic static int indexOf(byte[] outerArray, byte[] smallerArray) {
if (outerArray == null || smallerArray == null || outerArray.length == 0 ||
smallerArray.length == 0 || outerArray.length < smallerArray.length) {
// Guard against input that might throw nasty runtime exceptions!
return -1;
}
for (int i = 0; i < outerArray.length - smallerArray.length + 1; ++i) {
boolean found = true;
for (int j = 0; j < smallerArray.length; ++j) {
if (outerArray[i + j] != smallerArray[j]) {
found = false;
break;
}
}
if (found) {
return i;
}
}
return -1;
}