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