Here you can find the source of regionMatches(byte[] ba1, int pos1, byte[] ba2, int pos2, int len)
Parameter | Description |
---|---|
ba1 | the first set of bytes |
pos1 | the starting position within the first set bytes |
ba2 | the second set of bytes |
pos2 | the starting position within the second set bytes |
len | the number of bytes to compare |
true
if the specified sub-region of the first set of bytes matches the specified sub-region of the second set of bytes false
otherwise.
public static final boolean regionMatches(byte[] ba1, int pos1, byte[] ba2, int pos2, int len)
//package com.java2s; /*//from w w w .j av a2 s. c o m * Copyright SparseWare Inc. 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. */ public class Main { /** * Tests if two byte regions are equal. * * @param ba1 the first set of bytes * @param pos1 the starting position within the first set bytes * @param ba2 the second set of bytes * @param pos2 the starting position within the second set bytes * @param len the number of bytes to compare * * @return <code>true</code> if the specified sub-region of the first set of bytes * matches the specified sub-region of the second set of bytes <code>false</code> * otherwise. */ public static final boolean regionMatches(byte[] ba1, int pos1, byte[] ba2, int pos2, int len) { int to = +pos1; int po = pos2; // Note: toffset, ooffset, or len might be near -1>>>1. if ((pos2 < 0) || (pos1 < 0) || (pos1 > ((long) ba1.length - len)) || (pos2 > ((long) ba2.length - len))) { return false; } while (len-- > 0) { byte c1 = ba1[to++]; byte c2 = ba2[po++]; if (c1 == c2) { continue; } return false; } return true; } }