Java Array arrayEndsWith(final byte[] array, final byte[] str)

Here you can find the source of arrayEndsWith(final byte[] array, final byte[] str)

Description

Check that a byte array ends with some byte values.

License

Apache License

Parameter

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

Exception

Parameter Description
NullPointerException if any argument is null

Return

true if the string is the end sequence of the array, false otherwise

Declaration

public static boolean arrayEndsWith(final byte[] array, final byte[] str) 

Method Source Code

//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;
    }
}

Related

  1. array_equals(byte[] foo, byte bar[])
  2. array_int2float(int ai[])
  3. array_intAddLimit(int[] in, int value, int limit)
  4. arrayed(int arrays, String inner)
  5. arrayExclude(double[] src, int excludeIndex)
  6. arrayFirstIndexOf(final T[] array, final T value)
  7. arrayFlatten(final int[][] arr)
  8. arrayGetCenter(byte[] array, int location, int length)