Package ch.threema.apitool.utils
Class DataUtils
java.lang.Object
ch.threema.apitool.utils.DataUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayToHexString(byte[] bytes) Convert a byte array into a hexadecimal string (lowercase).static longbyteArrayToLongBigEndian(byte[] bytes) static StringextractQuote(String text, QuotePart part) static byte[]Convert a string in hexadecimal representation to a byte array.static byte[]longToByteArrayBigEndian(long value) static byte[]readHexFile(File inFile) Read hexadecimal data from a file and return it as a byte array.static KeyreadKeyFile(File inFile) Read an encoded key from a file and return it as a key instance.static KeyreadKeyFile(File inFile, String expectedKeyType) Read an encoded key from a file and return it as a key instance.static voidwriteHexFile(File outFile, byte[] data) Write a byte array into a file in hexadecimal format.static voidwriteKeyFile(File outFile, Key key) Write an encoded key to a file Encoded key format: type:hex_key.
-
Field Details
-
QUOTE_PATTERN
- See Also:
-
-
Constructor Details
-
DataUtils
public DataUtils()
-
-
Method Details
-
hexStringToByteArray
Convert a string in hexadecimal representation to a byte array.Whitespace (RegEx \s) is stripped before decoding, but if other invalid characters are contained, an error is thrown.
- Parameters:
s- hex string- Returns:
- decoded byte array
- Throws:
InvalidHexException- if the string is not a valid hex string
-
byteArrayToHexString
Convert a byte array into a hexadecimal string (lowercase).- Parameters:
bytes- the bytes to encode- Returns:
- hex encoded string
-
longToByteArrayBigEndian
public static byte[] longToByteArrayBigEndian(long value) -
byteArrayToLongBigEndian
public static long byteArrayToLongBigEndian(byte[] bytes) -
readHexFile
Read hexadecimal data from a file and return it as a byte array.- Parameters:
inFile- input file- Returns:
- the decoded data
- Throws:
IOException
-
writeHexFile
Write a byte array into a file in hexadecimal format.- Parameters:
outFile- output filedata- the data to be written- Throws:
IOException
-
readKeyFile
Read an encoded key from a file and return it as a key instance.- Parameters:
inFile- input file- Returns:
- the decoded key
- Throws:
IOExceptionInvalidKeyException
-
readKeyFile
public static Key readKeyFile(File inFile, String expectedKeyType) throws IOException, InvalidKeyException Read an encoded key from a file and return it as a key instance.- Parameters:
inFile- input fileexpectedKeyType- validates the key type (private or public)- Returns:
- the decoded key
- Throws:
IOExceptionInvalidKeyException
-
writeKeyFile
Write an encoded key to a file Encoded key format: type:hex_key.- Parameters:
outFile- output filekey- a key that will be encoded and written to a file- Throws:
IOException
-
extractQuote
-