Here you can find the source of startsWith(byte[] array, byte[] prefix)
Parameter | Description |
---|---|
array | The array to check |
prefix | The prefix bytes to test for |
public static boolean startsWith(byte[] array, byte[] prefix)
//package com.java2s; /**//from ww w . j a v a2s . com * Geotag * Copyright (C) 2007-2016 Andreas Schneider * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Utility method to check if one byte array starts with a specified sequence * of bytes. * * @param array * The array to check * @param prefix * The prefix bytes to test for * @return true if the array starts with the bytes from the prefix */ public static boolean startsWith(byte[] array, byte[] prefix) { if (array == prefix) { return true; } if (array == null || prefix == null) { return false; } int prefixLength = prefix.length; if (prefix.length > array.length) { return false; } for (int i = 0; i < prefixLength; i++) { if (array[i] != prefix[i]) { return false; } } return true; } }