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 Summary

    Modifier and Type
    Method
    Description
    static byte[]
    bytesToHexBytes(byte[] bytes)
    Returns the hexadecimal digits representing the supplied byte array.
    static String
    bytesToHexStr(byte[] bytes)
    Returns an hexadecimal string representing the supplied byte array.
    static byte[]
    compressBytes(byte[] bytes)
    Returns a compressed representation of the supplied bytes.
    static byte[]
    compressBytes(byte[] bytes, int offset, int length)
    Returns a compressed representation of the specified byte range.
    static String
    Returns the string representation of the supplied throwable.
    static byte[]
    Returns the byte array represented by supplied hexadecimal string.
    static int
    hexToNibble(char hexchr)
    Returns the nibble (4-bits) of the supplied hexadecimal char.
    static String
    Returns a copy of a string with trailing spaces ' ' removed.
    static byte[]
    uncompressBytes(byte[] bytes)
    Returns an uncompressed representation of the supplied bytes.
    static byte[]
    uncompressBytes(byte[] bytes, int offset, int length)
    Returns an uncompressed representation of the specified byte range.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • uncompressBytes

      public static byte[] uncompressBytes(byte[] bytes)
      Returns an uncompressed representation of the supplied bytes.
      Parameters:
      bytes - the bytes to be uncompressed.
      Returns:
      an uncompressed representation of the supplied bytes.
      Throws:
      NullPointerException - if bytes is null.
      IllegalArgumentException - if an argument is invalid.
    • uncompressBytes

      public static byte[] uncompressBytes(byte[] bytes, int offset, int length)
      Returns an uncompressed representation of the specified byte range.
      Parameters:
      bytes - the bytes to be uncompressed.
      offset - the index of the first byte to uncompress.
      length - the total number of bytes to uncompress.
      Returns:
      an uncompressed representation of the specified byte range.
      Throws:
      NullPointerException - if bytes is null.
      IllegalArgumentException - if an argument is invalid.
    • compressBytes

      public static byte[] compressBytes(byte[] bytes)
      Returns a compressed representation of the supplied bytes.
      Parameters:
      bytes - the bytes to be compressed.
      Returns:
      a compressed representation of the supplied bytes.
      Throws:
      NullPointerException - if bytes is null.
      IllegalArgumentException - if an argument is invalid.
    • compressBytes

      public static byte[] compressBytes(byte[] bytes, int offset, int length)
      Returns a compressed representation of the specified byte range.
      Parameters:
      bytes - the bytes to be compressed.
      offset - the index of the first byte to compress.
      length - the total number of bytes to compress.
      Returns:
      a compressed representation of the specified byte range.
      Throws:
      NullPointerException - if bytes is null.
      IllegalArgumentException - if an argument is invalid.
    • 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.