public int indexOf()

in ch-commons-util/src/main/java/com/cloudhopper/commons/util/ByteBuffer.java [921:948]


    public int indexOf(byte[] bytes, int offset) {
        // make sure we're not checking against any byte arrays of length 0
        if (bytes.length == 0 || size() == 0) {
            // a match is not possible
            return -1;
        }
        
        // make sure the offset won't cause us to read past the end of the byte[]
        if (offset < 0 || offset >= size()) {
            throw new IllegalArgumentException("Offset must be a value between 0 and " + size() + " (current buffer size)");
        }

        int length = size()-bytes.length;
        for (int i = offset; i <= length; i++) {
            int j = 0;
            // continue search loop while the next bytes match
            while (j < bytes.length && getUnchecked(i+j) == bytes[j]) {
                j++;
            }
            // if we found it, then j will equal the length of the search bytes
            if (j == bytes.length) {
                return i;
            }
        }

        // if we get here then we didn't find it
        return -1;
    }