Class Convert

java.lang.Object
cl.netswitch.lib.util.Convert

public final class Convert extends Object
Provides static utility methods that perform general conversions.
  • Method Details

    • rightTrim

      public static String rightTrim(String str)
      Returns a copy of a string with trailing spaces ' ' removed.
      Parameters:
      str - the string to be right-trimmed.
      Returns:
      a copy of a string with trailing spaces ' ' removed.
      Throws:
      NullPointerException - if str is null.
    • getMessages

      public static String getMessages(Throwable thrown)
      Returns the string representation of the supplied throwable.
      Parameters:
      thrown - the throwable to convert to a string (can be null).
      Returns:
      the string representation of the supplied throwable.
    • bytesToHexStr

      public static String bytesToHexStr(byte[] bytes)
      Returns an hexadecimal string representing the supplied byte array.
      Parameters:
      bytes - the bytes to convert to an hexadecimal representation.
      Returns:
      an hexadecimal string representation of supplied byte array.
      Throws:
      NullPointerException - if bytes is null.
    • bytesToHexBytes

      public static byte[] bytesToHexBytes(byte[] bytes)
      Returns the hexadecimal digits representing the supplied byte array.
      Parameters:
      bytes - the bytes to be converted to hexadecimal digits.
      Returns:
      the hexadecimal digits representing the supplied byte array.
      Throws:
      NullPointerException - if bytes is null.
    • hexToBytes

      public static byte[] hexToBytes(String hexstr)
      Returns the byte array represented by supplied hexadecimal string.
      Parameters:
      hexstr - the hexadecimal string to be converted.
      Returns:
      the byte array represented by supplied hexadecimal string.
      Throws:
      NullPointerException - if hexstr is null.
      IllegalArgumentException - if hexstr is invalid.
    • hexToNibble

      public static int hexToNibble(char hexchr)
      Returns the nibble (4-bits) of the supplied hexadecimal char.
      Parameters:
      hexchr - the hexadecimal character.
      Returns:
      the nibble (4-bits) of the supplied hexchr char.
      Throws:
      IllegalArgumentException - if hexchr is invalid.