字節數組工具

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