Here you can find the source of arrayEndsWith(final byte[] array, final byte[] str)
Parameter | Description |
---|---|
array | array to be checked, must not be null |
str | a byte string which will be checked as the end sequence of the array, must not be null |
Parameter | Description |
---|---|
NullPointerException | if any argument is null |
public static boolean arrayEndsWith(final byte[] array, final byte[] str)
//package com.java2s; /* /*from ww w.j av a 2 s . com*/ * Copyright 2014 Igor Maznitsa (http://www.igormaznitsa.com). * * 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 { /** * Check that a byte array ends with some byte values. * * @param array array to be checked, must not be null * @param str a byte string which will be checked as the end sequence of the * array, must not be null * @return true if the string is the end sequence of the array, false * otherwise * @throws NullPointerException if any argument is null * @since 1.1 */ public static boolean arrayEndsWith(final byte[] array, final byte[] str) { boolean result = false; if (array.length >= str.length) { result = true; int index = str.length; int arrindex = array.length; while (--index >= 0) { if (array[--arrindex] != str[index]) { result = false; break; } } } return result; } }