字节数组实用程序
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) 从给定的字节中获取字符串。 |
公共构造函数
字节数组实用程序
public ByteArrayUtil ()
公共方法
获取整数
public static int getInt (byte[] bytes, int offset, int length)
从给定的字节中获取一个整数。
java没有无符号值类型,因此需要扩展将存储在2个字节中的无符号短整型值转换为整数值。
参数 | |
---|---|
bytes | byte :字节数组。 |
offset | int :整数数据的起始偏移量。 |
length | int :整数数据的长度。 |
退货 | |
---|---|
int | 给定字节的 int 值。 |
长
public static long getLong (byte[] bytes, int offset, int length)
从给定的字节中获取长整型值。
java没有无符号值类型,因此需要扩展将存储在4个字节中的无符号整数转换为long值。
参数 | |
---|---|
bytes | byte :字节数组。 |
offset | int :长整型值的起始偏移量。 |
length | int :长整型值的长度。 |
退货 | |
---|---|
long | 给定字节的长值。 |
获取字符串
public static String getString (byte[] bytes, int offset, int length)
从给定的字节中获取字符串。
参数 | |
---|---|
bytes | byte :字节数组。 |
offset | int :字符串数据的起始偏移量。 |
length | int :字符串数据的长度。 |
退货 | |
---|---|
String |