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 個位元組中的未簽署 short 轉換為整數值。

參數
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:Long 值的起始偏移量。

length int:長值的長度。

傳回
long 從指定位元組取得的長值。

getString

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

從指定的位元組取得字串。

參數
bytes byte:位元組陣列。

offset int:字串資料的起始偏移量。

length int:字串資料的長度。

傳回
String