Here you can find the source of startsWith(byte[] haystack, byte[] needle)
Parameter | Description |
---|---|
haystack | byte array to search thru looking for the needle |
needle | what we want to find in the haystack |
public static boolean startsWith(byte[] haystack, byte[] needle)
//package com.java2s; /**/*from w w w . ja v a2s.c o m*/ * static byte array utilities * * Copyright (c) 2004, Pat Farrell, All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * compare byte arrays * @return true if equal * @param haystack byte array to search thru looking for the needle * @param needle what we want to find in the haystack */ public static boolean startsWith(byte[] haystack, byte[] needle) { int i; for (i = 0; i < needle.length; i++) if (needle[i] != haystack[i]) break; return i == needle.length; } /** compare byte arrays * @return true if equal * @param offset offset into haystack * @param haystack byte array to search thru looking for the needle * @param needle what we want to find in the haystack */ public static boolean startsWith(byte[] haystack, int offset, byte[] needle) { int i; for (i = 0; i < needle.length; i++) if (needle[i] != haystack[i + offset]) break; return i == needle.length; } }