java.lang.Object
org.seppiko.commons.utils.codec.HexUtil

public class HexUtil extends Object
Hex (Base16) Encoder / Decoder Util.
Author:
Leonard Woo
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char[]
    Hexadecimal character array with lower letters
    static final int
    Hexadecimal length
    static final char[]
    Hexadecimal character array with upper letters
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    decode(char[] data)
    convert hex char array to byte array
    static byte[]
    decode(String data, String split)
    convert hex string with split to byte array
    static byte[]
    convert hex string with whitespace split to byte array
    static char[]
    encode(byte[] data)
    convert byte array to hex char array
    static char[]
    encode(byte[] data, boolean toLowerCase)
    convert byte array to hex char array
    static String
    encodeString(byte[] data)
    convert byte array to string object
    static String
    encodeString(byte[] data, String split)
    convert byte array to string object
    static char[]
    encodeWithBytes(byte[] data)
    convert byte array to hex char array
    static int
    hexDigit(char ch)
    Returns the numeric value of the hexadecimal character ch

    Methods inherited from class java.lang.Object

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

    • HEXADECIMAL_LENGTH

      public static final int HEXADECIMAL_LENGTH
      Hexadecimal length
      See Also:
    • HEXADECIMAL

      public static final char[] HEXADECIMAL
      Hexadecimal character array with lower letters
    • HEXADECIMAL_UPPER

      public static final char[] HEXADECIMAL_UPPER
      Hexadecimal character array with upper letters
  • Method Details

    • hexDigit

      public static int hexDigit(char ch)
      Returns the numeric value of the hexadecimal character ch
      Parameters:
      ch - the character to be converted
      Returns:
      the numeric value represented by the hexadecimal character
      See Also:
    • encodeWithBytes

      public static char[] encodeWithBytes(byte[] data)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      Returns:
      hex char array
    • encodeString

      public static String encodeString(byte[] data)
      convert byte array to string object
      Parameters:
      data - byte array data
      Returns:
      string object
    • encodeString

      public static String encodeString(byte[] data, String split)
      convert byte array to string object
      Parameters:
      data - byte array data
      split - string object split
      Returns:
      string object
    • encode

      public static char[] encode(byte[] data)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      Returns:
      hex char array
    • encode

      public static char[] encode(byte[] data, boolean toLowerCase)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      toLowerCase - true is lower case, false is upper case
      Returns:
      hex char array
    • decodeString

      public static byte[] decodeString(String data)
      convert hex string with whitespace split to byte array
      Parameters:
      data - hex string
      Returns:
      byte array
      Throws:
      IllegalArgumentException - data include invalid character
      NullPointerException - when data or separator is null
    • decode

      public static byte[] decode(String data, String split) throws IllegalArgumentException, NullPointerException
      convert hex string with split to byte array
      Parameters:
      data - hex string
      split - split
      Returns:
      byte array
      Throws:
      IllegalArgumentException - data include invalid character
      NullPointerException - when data or separator is null
    • decode

      public static byte[] decode(char[] data) throws IllegalArgumentException, NullPointerException
      convert hex char array to byte array
      Parameters:
      data - hex char array
      Returns:
      byte array
      Throws:
      IllegalArgumentException - data include invalid character
      NullPointerException - data is null or empty