Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Stay organized with collections
Save and categorize content based on your preferences.
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 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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-03-08 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-03-08 UTC."],[],[],null,["# ByteArrayUtil\n=============\n\n\n`\npublic\n\n\nclass\nByteArrayUtil\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|-----------------------------------------|\n| java.lang.Object ||\n| ↳ | com.android.tradefed.util.ByteArrayUtil |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nUtilities to operate on byte array, e.g., convert bytes to integer.\n\nJava doesn't have an unsigned value type, so expansion is needed to convert an unsigned\ninteger stored in 4 bytes to a long value, or unsigned short stored in 2 bytes to an integer\nvalue.\n\nSummary\n-------\n\n| ### Public constructors ||\n|----------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[ByteArrayUtil](../../../../../../reference/tradefed/com/android/tradefed/util/ByteArrayUtil.html#ByteArrayUtil())`() ` |\n\n| ### Public methods ||\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static int` | ` `[getInt](../../../../../../reference/tradefed/com/android/tradefed/util/ByteArrayUtil.html#getInt(byte[],%20int,%20int))`(byte[] bytes, int offset, int length) ` Get an integer from the given bytes. |\n| ` static long` | ` `[getLong](../../../../../../reference/tradefed/com/android/tradefed/util/ByteArrayUtil.html#getLong(byte[],%20int,%20int))`(byte[] bytes, int offset, int length) ` Get a long value from the given bytes. |\n| ` static String` | ` `[getString](../../../../../../reference/tradefed/com/android/tradefed/util/ByteArrayUtil.html#getString(byte[],%20int,%20int))`(byte[] bytes, int offset, int length) ` Get the string from the given bytes. |\n\nPublic constructors\n-------------------\n\n### ByteArrayUtil\n\n```\npublic ByteArrayUtil ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### getInt\n\n```\npublic static int getInt (byte[] bytes, \n int offset, \n int length)\n```\n\nGet an integer from the given bytes.\n\njava doesn't have an unsigned value type, so expansion is needed to convert an unsigned\nshort stored in 2 bytes to an integer value.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------------------------------------------|\n| `bytes` | `byte`: an array of bytes. \u003cbr /\u003e |\n| `offset` | `int`: the start offset of the integer data. \u003cbr /\u003e |\n| `length` | `int`: the length of the integer data. \u003cbr /\u003e |\n\n| Returns ||\n|-------|-------------------------------------------|\n| `int` | an int value from the given bytes. \u003cbr /\u003e |\n\n### getLong\n\n```\npublic static long getLong (byte[] bytes, \n int offset, \n int length)\n```\n\nGet a long value from the given bytes.\n\njava doesn't have an unsigned value type, so expansion is needed to convert an unsigned\ninteger stored in 4 bytes to a long value.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|---------------------------------------------------|\n| `bytes` | `byte`: an array of bytes. \u003cbr /\u003e |\n| `offset` | `int`: the start offset of the long value. \u003cbr /\u003e |\n| `length` | `int`: the length of the long value. \u003cbr /\u003e |\n\n| Returns ||\n|--------|-------------------------------------------|\n| `long` | a long value from the given bytes. \u003cbr /\u003e |\n\n### getString\n\n```\npublic static String getString (byte[] bytes, \n int offset, \n int length)\n```\n\nGet the string from the given bytes.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|----------------------------------------------------|\n| `bytes` | `byte`: an array of bytes. \u003cbr /\u003e |\n| `offset` | `int`: the start offset of the string data. \u003cbr /\u003e |\n| `length` | `int`: the length of the string data. \u003cbr /\u003e |\n\n| Returns ||\n|----------|--------|\n| `String` | \u003cbr /\u003e |"]]