Here you can find the source of compare(byte[] a, int a_pos, byte[] b, int b_pos, int length)
Parameter | Description |
---|---|
a | a parameter |
a_pos | a parameter |
b | a parameter |
b_pos | a parameter |
length | a parameter |
public static boolean compare(byte[] a, int a_pos, byte[] b, int b_pos, int length)
//package com.java2s; public class Main { /**//from w ww. jav a 2 s . c om * Compare tow bytearrays. * * @param a * @param b * @return true if contents of two byte array are match. */ public static boolean compare(byte[] a, byte[] b) { if (a == null || b == null) { return a == b; } if (a.length != b.length) { return false; } for (int i = 0; i < a.length; i++) { if (a[i] != b[i]) { return false; } } return true; } /** * Compare parts of bytearrays. * * @param a * @param a_pos * @param b * @param b_pos * @param length * @return true if match. */ public static boolean compare(byte[] a, int a_pos, byte[] b, int b_pos, int length) { if (a == null || b == null) { return length == 0; } if ((a.length < a_pos + length) || (b.length < b_pos + length)) { return false; } for (int i = 0; i < length; i++) { if (a[a_pos + i] != b[b_pos + i]) { return false; } } return true; } }