/**
* 判断两个 ByteArray 是否相等。
*
* @param a 一个 ByteArray。
* @param b 另一个 ByteArray。
* @return 如果相等,返回 true;否则返回 false。
*/
public static function eqByteArray(a:ByteArray, b:ByteArray):Boolean {
if(a.length != b.length) {
return false;
}
var posA:int = a.position;
var posB:int = b.position;
var result:Boolean = true;
a.position = b.position = 0;
while(a.bytesAvailable >= 4) {
if(a.readUnsignedInt() != b.readUnsignedInt()) {
result = false;
break;
}
}
if(result && a.bytesAvailable != 0) {
var last:int = a.bytesAvailable;
result =
last == 1 ? a.readByte() == b.readByte() :
last == 2 ? a.readShort() == b.readShort() :
last == 3 ? a.readShort() == b.readShort()
&& a.readByte() == b.readByte() :
true;
}
a.position = posA;
b.position = posB;
return result;
}
本文链接:http://assnippets.blogspot.com/2008/01/as3-bytearray.html转载请注明出处。
相关文章:
0评论:
发表评论