Java Byte Array Equal bytesEqual(final byte[] source, final int offset, final byte[] target)

Here you can find the source of bytesEqual(final byte[] source, final int offset, final byte[] target)

Description

Utility method to determine whether a subarray of bytes in a byte-array source matches the byte-array in target.

License

Apache License

Parameter

Parameter Description
source The source byte array
offset The offset of the sub-array within the source.
target The target byte array

Return

true if the byte subarrays are equal

Declaration

public static boolean bytesEqual(final byte[] source, final int offset, final byte[] target) 

Method Source Code

//package com.java2s;
/**/*w  w w  .  ja  v a 2 s.com*/
 * Copyright 2005-2012 Akiban Technologies, Inc.
 * 
 * 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 {
    /**
     * Utility method to determine whether a subarray of bytes in a byte-array
     * <code>source</code> matches the byte-array in <code>target</code>.
     * 
     * @param source
     *            The source byte array
     * @param offset
     *            The offset of the sub-array within the source.
     * @param target
     *            The target byte array
     * @return <code>true</code> if the byte subarrays are equal
     */
    public static boolean bytesEqual(final byte[] source, final int offset, final byte[] target) {
        for (int index = 0; index < target.length; index++) {
            if (source[index + offset] != target[index]) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. bytesEqual(byte[] a1, byte[] a2)
  2. bytesEqual(byte[] a1, byte[] a2)
  3. bytesEqual(byte[] buf1, byte[] buf2, int off, int len)
  4. bytesEqual(final byte[] a, final byte[] b)
  5. bytesEqual(final byte[] b1, final int j, final byte[] b2, final int k, final int len)