Class HexUtils


  • public final class HexUtils
    extends java.lang.Object
    Tables useful when converting byte arrays to and from strings of hexadecimal digits. Code from Ajp11, from Apache's JServ.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] fromHexString​(java.lang.String input)
      Convert a hexadecimal string to a byte array.
      static int getDec​(int index)
      Get the decimal value of the character at the given index.
      static byte getHex​(int index)
      Get the hexadecimal byte for the given index.
      static java.lang.String toHexString​(byte[] bytes)
      Convert a byte array to a hexadecimal string representation.
      static java.lang.String toHexString​(char c)
      Convert a character to a hexadecimal string representation.
      • Methods inherited from class java.lang.Object

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

      • getDec

        public static int getDec​(int index)
        Get the decimal value of the character at the given index.
        Parameters:
        index - the character index
        Returns:
        the decimal value, or -1 if the character is not a valid hex digit
      • getHex

        public static byte getHex​(int index)
        Get the hexadecimal byte for the given index.
        Parameters:
        index - the index into the hex table
        Returns:
        the hexadecimal byte
      • toHexString

        public static java.lang.String toHexString​(char c)
        Convert a character to a hexadecimal string representation.
        Parameters:
        c - the character to convert
        Returns:
        the hexadecimal string representation of the character
      • toHexString

        public static java.lang.String toHexString​(byte[] bytes)
        Convert a byte array to a hexadecimal string representation.
        Parameters:
        bytes - the byte array to convert
        Returns:
        the hexadecimal string, or null if the input is null
      • fromHexString

        public static byte[] fromHexString​(java.lang.String input)
        Convert a hexadecimal string to a byte array.
        Parameters:
        input - the hexadecimal string to convert
        Returns:
        the byte array, or null if the input is null
        Throws:
        java.lang.IllegalArgumentException - if the input has an odd number of characters or contains non-hexadecimal characters