ByteArrayUtil
public
class
ByteArrayUtil
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.ByteArrayUtil |
Utilities to operate on byte array, e.g., convert bytes to integer.
Java doesn't have an unsigned value type, so expansion is needed to convert an unsigned integer stored in 4 bytes to a long value, or unsigned short stored in 2 bytes to an integer value.
Summary
Public constructors | |
|---|---|
ByteArrayUtil()
|
|
Public methods | |
|---|---|
static
int
|
getInt(byte[] bytes, int offset, int length)
Get an integer from the given bytes. |
static
long
|
getLong(byte[] bytes, int offset, int length)
Get a long value from the given bytes. |
static
String
|
getString(byte[] bytes, int offset, int length)
Get the string from the given bytes. |
Public constructors
ByteArrayUtil
public ByteArrayUtil ()
Public methods
getInt
public static int getInt (byte[] bytes,
int offset,
int length)Get an integer from the given bytes.
java doesn't have an unsigned value type, so expansion is needed to convert an unsigned short stored in 2 bytes to an integer value.
| Parameters | |
|---|---|
bytes |
byte: an array of bytes. |
offset |
int: the start offset of the integer data. |
length |
int: the length of the integer data. |
| Returns | |
|---|---|
int |
an int value from the given bytes. |
getLong
public static long getLong (byte[] bytes,
int offset,
int length)Get a long value from the given bytes.
java doesn't have an unsigned value type, so expansion is needed to convert an unsigned integer stored in 4 bytes to a long value.
| Parameters | |
|---|---|
bytes |
byte: an array of bytes. |
offset |
int: the start offset of the long value. |
length |
int: the length of the long value. |
| Returns | |
|---|---|
long |
a long value from the given bytes. |
getString
public static String getString (byte[] bytes,
int offset,
int length)Get the string from the given bytes.
| Parameters | |
|---|---|
bytes |
byte: an array of bytes. |
offset |
int: the start offset of the string data. |
length |
int: the length of the string data. |
| Returns | |
|---|---|
String |
|