Class DataUtils

java.lang.Object
ch.threema.apitool.utils.DataUtils

public class DataUtils extends Object
  • Field Details

  • Constructor Details

    • DataUtils

      public DataUtils()
  • Method Details

    • hexStringToByteArray

      public static byte[] hexStringToByteArray(String s) throws InvalidHexException
      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

      public static String byteArrayToHexString(byte[] bytes)
      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

      public static byte[] readHexFile(File inFile) throws IOException
      Read hexadecimal data from a file and return it as a byte array.
      Parameters:
      inFile - input file
      Returns:
      the decoded data
      Throws:
      IOException
    • writeHexFile

      public static void writeHexFile(File outFile, byte[] data) throws IOException
      Write a byte array into a file in hexadecimal format.
      Parameters:
      outFile - output file
      data - the data to be written
      Throws:
      IOException
    • readKeyFile

      public static Key readKeyFile(File inFile) throws IOException, InvalidKeyException
      Read an encoded key from a file and return it as a key instance.
      Parameters:
      inFile - input file
      Returns:
      the decoded key
      Throws:
      IOException
      InvalidKeyException
    • 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 file
      expectedKeyType - validates the key type (private or public)
      Returns:
      the decoded key
      Throws:
      IOException
      InvalidKeyException
    • writeKeyFile

      public static void writeKeyFile(File outFile, Key key) throws IOException
      Write an encoded key to a file Encoded key format: type:hex_key.
      Parameters:
      outFile - output file
      key - a key that will be encoded and written to a file
      Throws:
      IOException
    • extractQuote

      public static String extractQuote(String text, QuotePart part)