public final class ByteUtils extends Object
ByteUtils class is a collection of utility class fields and methods
for byte array handling.| Modifier and Type | Field and Description |
|---|---|
static int |
HEX_RADIX
Radix to be used in intepreting a hex string.
|
static String |
HEX_SEPARATOR
Separator for octets in a hex string.
|
static char |
HEX_SEPARATOR_CHAR
A character that separates octets in a hex string.
|
static com.google.common.base.CharMatcher |
HEX_SEPARATOR_MATCHER
A CharMatcher which matches on ':'.
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
getBits(byte[] data,
int off,
int nbits)
Read the specified number of bits from the given byte array.
|
static int |
parseHexOctet(String hex)
Convert the given hex string as unsigned byte.
|
static void |
setBits(byte[] output,
byte[] input,
int off,
int nbits)
Copy bits in the specified input byte array into the specified output
array.
|
static byte[] |
toBytes(String hex)
Convert the given hex string with ":" inserted into a byte array.
|
static String |
toHexString(byte[] bytes)
Convert the given byte array into hex string with ":" inserted.
|
public static final char HEX_SEPARATOR_CHAR
public static final String HEX_SEPARATOR
public static final com.google.common.base.CharMatcher HEX_SEPARATOR_MATCHER
public static final int HEX_RADIX
public static String toHexString(byte[] bytes)
Note that this method returns null if null is passed.
bytes - A byte array.public static byte[] toBytes(String hex)
null is returned if null is passed.hex - A hex string with ":" inserted.NumberFormatException - The given string is not a hex string.public static int parseHexOctet(String hex)
hex - A hex string.NumberFormatException - The given string could not be converted into an unsigned byte.public static byte[] getBits(byte[] data,
int off,
int nbits)
data - A byte array.
Specifying null results in undefined behavior.off - The bit offset to start fetching bits.nbits - The number of bits to be fetched.public static void setBits(byte[] output,
byte[] input,
int off,
int nbits)
output - A byte array to store bits.
Specifying null results in undefined behavior.input - A byte array to be copied.
Bits in this array are expected to be aligned to LSB.
Specifying null results in undefined behavior.off - The bit offset of output to start inserting bits
from input.nbits - The number of bits to be copied.Copyright © 2018 OpenDaylight. All rights reserved.