Class Util

java.lang.Object
i5.las2peer.registry.Util

public class Util extends Object
Helper methods mostly for converting data.
  • Method Details

    • padAndConvertString

      public static byte[] padAndConvertString(String string, int desiredLength)
      Converts string to byte array, padded with zero bytes, using UTF-8 encoding.
      Parameters:
      string - input string. Must be no longer than desiredLength
      desiredLength - length of the returned byte array
    • recoverString

      public static String recoverString(String hexString)
      Recovers string from byte-encoded hex string. (E.g., the hex strings in transactions / event logs.) Assumes UTF-8 encoding.
      Parameters:
      hexString - hexadecimal string containing Unicode
      Returns:
      decoded string
    • recoverString

      public static String recoverString(byte[] byteArray)
      Recovers string from byte array with possible leading zeros. Assumes UTF-8 encoding.
      Parameters:
      byteArray - Unicode byte array. Leading zeros are allowed and will be trimmed before decoding.
      Returns:
      decoded string
    • bytesToHexString

      public static String bytesToHexString(byte[] byteArray)
    • soliditySha3

      public static byte[] soliditySha3(String input)
      Computes Sha3 (= Keccak256) sum, hopefully matching the sum produced by Solidity's keccak256 and web3's soliditySha3.
      Parameters:
      input - arbitrary input string
      Returns:
      hash of input
    • parseVersion

      public static int[] parseVersion(String versionString)
      Converts version string ("x.y.z") to integers. If the string has the form "x.y" or "x", the unspecified components are assumed to be zero. (E.g., "1" = [1,0,0].)
      Parameters:
      versionString - version consisting of digits and up to three periods. Components must be parsable as Integers.
      Returns:
      equivalent version as int array of length three
    • unixtimeToString

      public static String unixtimeToString(long unixSeconds)
      Returns human-readable time string.
      Parameters:
      unixSeconds - Unix time in seconds
      Returns:
      date and time as string
    • getOrDefault

      public static <T> T getOrDefault(T value, T defaultValue)
      Returns the value of the first parameter if it is not null and the second param otherwise
      Parameters:
      value -
      defaultValue -
      Returns: