Package com.oss.util
Class HexTool
java.lang.Object
com.oss.util.HexTool
A utility class for converting binary data to a hexadecimal string.
- Since:
- ASN.1/Java 6.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getHex
(byte[] buffer) Get a string containing the hexadecimal representation of a buffer of binary data.static String
getHex
(byte[] buffer, int bytesPerLine) Get a string containing the hexadecimal representation of a buffer of binary data.static char
hexDigit
(int digit) Determines the character representation for a specified hexadecimal digit represented by integer value.static byte[]
Takes a string of hexadecimal digits and converts the string to a byte array.static byte[]
parseHstring
(String hexString) Takes a string that contains ASN.1 value notation for the OCTET STRING and converts it to the byte array.static void
printHex
(byte[] buffer) Print the hexadecimal representation of a buffer of binary data.static void
printHex
(byte[] buffer, int bytesPerLine) Print the hexadecimal representation of a buffer of binary data.
-
Constructor Details
-
HexTool
public HexTool()
-
-
Method Details
-
printHex
public static void printHex(byte[] buffer) Print the hexadecimal representation of a buffer of binary data. The output defaults to 32 bytes per line.- Parameters:
buffer
- a byte array of binary data.
-
printHex
public static void printHex(byte[] buffer, int bytesPerLine) Print the hexadecimal representation of a buffer of binary data.- Parameters:
buffer
- a byte array of binary data.bytesPerLine
- the number of bytes to print per line.
-
getHex
Get a string containing the hexadecimal representation of a buffer of binary data. The output defaults to 32 bytes per line.- Parameters:
buffer
- a byte array of binary data.- Returns:
- the string that contains the hexadecimal representation of the input binary data.
-
getHex
Get a string containing the hexadecimal representation of a buffer of binary data.- Parameters:
buffer
- a byte array of binary data.bytesPerLine
- the number of bytes to write per line.- Returns:
- the string that contains the hexadecimal representation of the input binary data.
-
parseHex
Takes a string of hexadecimal digits and converts the string to a byte array. The effect of the leftAlign parameter is as follows. When the hexString has an odd number of hexadecimal digits, the parameter instructs the method where to place the padding nibble:Let the hexString is "123": leftAlign byte[] returned ------------------------------- true {0x12, 0x30} false {0x01, 0x23}
- Parameters:
hexString
- string of hexadecimal digits to convert to a byte array.leftAlign
- specifies where the padding nibble should occur in case when the input string contains odd number of hexadecimal characters.- Returns:
- the result byte array.
- Throws:
NumberFormatException
- if the hexString contains invalid characters.
-
parseHstring
Takes a string that contains ASN.1 value notation for the OCTET STRING and converts it to the byte array. This byte array can be passed either to the OctetString constructor or to the setValue() method of the OctetString class.- Parameters:
hexString
- string, that contains value notation. E.g. '010203'H.- Returns:
- the result byte array
- Throws:
NumberFormatException
- if the string does not contain valid value notation for the OCTET STRING.
-
hexDigit
public static char hexDigit(int digit) Determines the character representation for a specified hexadecimal digit represented by integer value.- Parameters:
digit
- integer in the range of 0..15.- Returns:
- character representation of the digit. The '\0' is returned if the digit is out of range.
-