Class HexString

java.lang.Object
eu.ill.webx.utils.HexString

public class HexString extends Object
Utility class to convert binary bytearrays into hexadecimal strings and vice versa.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    fromByteArray(byte[] data)
    Converts byte data to hex string
    static String
    fromByteArray(byte[] data, int length)
    Converts byte data to hex string using a maximum length of the data
    static byte[]
    toByteArray(String hexString, int expectedBytesLength)
    Converts from a hexadecimal string to a byte array.
    static String
    toDebugString(byte[] data)
    Converts byte data to a hex string using full length of byte data.
    static String
    toDebugString(byte[] data, int length)
    Converts byte data to hex string using a fixed maximum length of data The data is formatted for easier debugging.

    Methods inherited from class java.lang.Object

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

    • HexString

      public HexString()
      Default constructor
  • Method Details

    • toDebugString

      public static String toDebugString(byte[] data)
      Converts byte data to a hex string using full length of byte data. The data is formatted for easier debugging.
      Parameters:
      data - the input binary data
      Returns:
      hexadecimal representation of the data
    • toDebugString

      public static String toDebugString(byte[] data, int length)
      Converts byte data to hex string using a fixed maximum length of data The data is formatted for easier debugging.
      Parameters:
      data - the input binary data
      length - The maximum length of the string
      Returns:
      hexadecimal representation of the data
    • fromByteArray

      public static String fromByteArray(byte[] data)
      Converts byte data to hex string
      Parameters:
      data - the input binary data
      Returns:
      hexadecimal representation of the data
    • fromByteArray

      public static String fromByteArray(byte[] data, int length)
      Converts byte data to hex string using a maximum length of the data
      Parameters:
      data - the input binary data
      length - The maximum length of the string
      Returns:
      hexadecimal representation of the data
    • toByteArray

      public static byte[] toByteArray(String hexString, int expectedBytesLength)
      Converts from a hexadecimal string to a byte array. Validation is made of the expected byte length.
      Parameters:
      hexString - the input hex string
      expectedBytesLength - the expected number of bytes
      Returns:
      the byte array equivalent to the hex string