public class Hex
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static char[] |
hexArray |
Constructor and Description |
---|
Hex() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
binaryStringToByteArray(java.lang.String stream)
converts a string of 0s and 1s to a byte array
|
static java.lang.String |
byteArrayToBitString(byte[] a)
Convert array of bytes into a binary string of 0s and 1s
|
static java.lang.String |
byteArrayToHexString(byte[] a)
Convert array of bytes into a hexadecimal string
|
static java.lang.String |
byteArrayToHexString(byte[] array,
int size) |
static byte[] |
byteListToByteArray(java.util.List<java.lang.Byte> blist)
Helper method to convert a list of bytes to an array
|
static java.lang.String |
bytesToHexString(byte[] array,
int bufSize)
Convert array of bytes into a hexadecimal string
|
static java.lang.String |
byteToBitString(byte n)
Converts a byte into binary string
|
static java.lang.String |
byteToHex(byte b)
Converts a byte into hexadecimal value
|
static byte[] |
convertTextToData(java.lang.String text)
Convert String to byte []
|
static byte[] |
decodeHex(char[] data) |
static char[] |
encodeHex(byte[] data)
Encode a byte array into a char array.
|
static char[] |
encodeHex(byte[] data,
boolean toLowerCase)
Encode a byte array into a char array.
|
protected static char[] |
encodeHex(byte[] data,
char[] toDigits)
Encode a byte array into a char array.
|
static java.lang.String |
encodeHexString(byte[] data)
Converts a byte array into an hexadecimal string
|
static byte[] |
hexStringToByteArray(java.lang.String s)
Convert a String to a byte array
|
static byte |
hexToByte(java.lang.String s)
Converts a hexadecimal String value into a byte
|
protected static int |
toDigit(char ch)
Returns the numeric value of the character
ch in hexadecimal. |
public static byte[] decodeHex(char[] data) throws java.lang.Exception
data
- (Eg. ['a', '9', 'c', ...])java.lang.Exception
- In case the number of characters is not even.public static char[] encodeHex(byte[] data)
data
- Data to be encoded (Eg. {10, 9, 12, ...})public static char[] encodeHex(byte[] data, boolean toLowerCase)
data
- Data to be encoded (Eg. {10, 9, 12, ...})toLowerCase
- True if result array needs to contains lowercase hexadecimal only.protected static char[] encodeHex(byte[] data, char[] toDigits)
data
- Data to be encoded (Eg. {10, 9, 12, ...})toDigits
- Char array of digits to be used on result.public static java.lang.String encodeHexString(byte[] data)
data
- Array of byte to be converted to a hex string. Eg. {10, 9, 12, ...}protected static int toDigit(char ch) throws java.lang.Exception
ch
in hexadecimal.ch
- the character to be converted.java.lang.Exception
- Illegal hexadecimal characterpublic static byte[] convertTextToData(java.lang.String text) throws GollumException
text
- string to convertGollumException
- Wrong conversion to byte arraypublic static java.lang.String bytesToHexString(byte[] array, int bufSize)
array
- Array of byte to be converted to a hex stringbufSize
- Size of bytes array.public static java.lang.String byteArrayToHexString(byte[] array, int size)
public static java.lang.String byteArrayToHexString(byte[] a)
a
- Array of byte to be converted to a hex stringpublic static java.lang.String byteArrayToBitString(byte[] a)
a
- Array of byte to be converted to a binary stringpublic static java.lang.String byteToHex(byte b)
b
- Byte to convertpublic static java.lang.String byteToBitString(byte n)
n
- Byte to be converted.public static byte hexToByte(java.lang.String s)
s
- String with a single hexadecimal value to convertpublic static byte[] hexStringToByteArray(java.lang.String s)
s
- String to be converted. Ex. "b64592..."public static byte[] binaryStringToByteArray(java.lang.String stream)
stream
- the string to be convertedpublic static byte[] byteListToByteArray(java.util.List<java.lang.Byte> blist)
blist
- A list of bytes to be converted.