Here you can find the source of indexOf(byte[] bytes, byte[] pattern, int start)
Parameter | Description |
---|---|
bytes | the byte array |
pattern | the pattern |
start | the start index from where to search |
public static int indexOf(byte[] bytes, byte[] pattern, int start)
//package com.java2s; /*//from www.j a va 2 s. com * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group */ public class Main { /** * Calculate the index of the first occurrence of the pattern in the byte array, starting with the given index. This methods returns -1 if the pattern has not been found, and the start position if the pattern is empty. * * @param bytes * the byte array * @param pattern * the pattern * @param start * the start index from where to search * @return the index */ public static int indexOf(byte[] bytes, byte[] pattern, int start) { if (pattern.length == 0) { return start; } if (start > bytes.length) { return -1; } int last = bytes.length - pattern.length + 1; next: for (; start < last; start++) { for (int i = 0; i < pattern.length; i++) { if (bytes[start + i] != pattern[i]) { continue next; } } return start; } return -1; } }