Package org.onlab.util
Class HexString
- java.lang.Object
-
- org.onlab.util.HexString
-
public final class HexString extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
fromHexString(java.lang.String values)
Convert a colon-separated hex string to byte array.static byte[]
fromHexString(java.lang.String values, java.lang.String separator)
Convert a hex-string with arbitrary separator to byte array.static java.lang.String
toHexString(byte[] bytes)
Convert a byte array to a colon-separated hex string.static java.lang.String
toHexString(byte[] bytes, java.lang.String separator)
Convert a byte array to a hex string separated by given separator.static java.lang.String
toHexString(long val)
Convert a long number to colon-separated hex string.static java.lang.String
toHexString(long val, int padTo)
Convert a long number to colon-separated hex string.static long
toLong(java.lang.String value)
Convert a colon-separated hex string to long.
-
-
-
Method Detail
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
Convert a byte array to a colon-separated hex string.- Parameters:
bytes
- byte array to be converted- Returns:
- converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef", or "(null)" if given byte array is null
-
toHexString
public static java.lang.String toHexString(byte[] bytes, java.lang.String separator)
Convert a byte array to a hex string separated by given separator.- Parameters:
bytes
- byte array to be convertedseparator
- the string use to separate each byte- Returns:
- converted hex string, or "(null)" if given byte array is null
-
toHexString
public static java.lang.String toHexString(long val, int padTo)
Convert a long number to colon-separated hex string. Prepend zero padding until given length.- Parameters:
val
- long number to be convertedpadTo
- prepend zeros until this length- Returns:
- converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef"
-
toHexString
public static java.lang.String toHexString(long val)
Convert a long number to colon-separated hex string. Prepend zero padding until 8 bytes.- Parameters:
val
- long number to be converted- Returns:
- converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef"
-
fromHexString
public static byte[] fromHexString(java.lang.String values)
Convert a colon-separated hex string to byte array.- Parameters:
values
- colon-separated hex string to be converted, e.g. "0f:ca:fe:de:ad:be:ef"- Returns:
- converted byte array
- Throws:
java.lang.NumberFormatException
- if input hex string cannot be parsed
-
fromHexString
public static byte[] fromHexString(java.lang.String values, java.lang.String separator)
Convert a hex-string with arbitrary separator to byte array. If separator is the empty string or null, then no separator will be considered.- Parameters:
values
- hex string to be convertedseparator
- regex for separator- Returns:
- converted byte array
- Throws:
java.lang.NumberFormatException
- if input hex string cannot be parsed
-
toLong
public static long toLong(java.lang.String value)
Convert a colon-separated hex string to long.- Parameters:
value
- colon-separated hex string to be converted, e.g. "00:0f:ca:fe:de:ad:be:ef"- Returns:
- converted long number
- Throws:
java.lang.NumberFormatException
- if input hex string cannot be parsed
-
-