ByteArrayUtil

public class ByteArrayUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.ByteArrayUtil


用于对字节数组进行操作的实用程序,例如将字节转换为整数。

Java 没有无符号值类型,因此需要进行扩展才能将存储在 4 个字节中的无符号整数转换为长整数值,或将存储在 2 个字节中的无符号短整数转换为整数值。

摘要

公共构造函数

ByteArrayUtil()

公共方法

static int getInt(byte[] bytes, int offset, int length)

从给定字节中获取一个整数。

static long getLong(byte[] bytes, int offset, int length)

从给定字节获取一个长值。

static String getString(byte[] bytes, int offset, int length)

从给定字节获取字符串。

公共构造函数

ByteArrayUtil

public ByteArrayUtil ()

公共方法

getInt

public static int getInt (byte[] bytes, 
                int offset, 
                int length)

从给定字节获取一个整数。

Java 没有无符号值类型,因此需要进行扩展才能将存储在 2 个字节中的无符号短整数转换为整数值。

参数
bytes byte:字节数组。

offset int:整数数据的起始偏移量。

length int:整数数据的长度。

返回
int 给定字节中的 int 值。

getLong

public static long getLong (byte[] bytes, 
                int offset, 
                int length)

从给定字节获取一个长值。

Java 没有无符号值类型,因此需要进行扩展才能将存储在 4 个字节中的无符号整数转换为长整数值。

参数
bytes byte:字节数组。

offset int:长值的起始偏移量。

length int:长值的长度。

返回
long 从给定字节中读取一个长值。

getString

public static String getString (byte[] bytes, 
                int offset, 
                int length)

从给定字节获取字符串。

参数
bytes byte:字节数组。

offset int:字符串数据的起始偏移量。

length int:字符串数据的长度。

返回
String