Class Conversion


  • public final class Conversion
    extends java.lang.Object
    Simple Data Conversion methods.

    Only small amounts of data should be converted using this class, to write a large number of bytes as a Base64 String, an alternative method such as IAIK's Base64OutputStream should be used, or javax.mail.internet.MimeUtility.

    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static byte[] base64StringToByteArray​(java.lang.String s)
      Deprecated.
      since 3.10, use Base64 instead.
      static java.lang.String byteArrayToBase64String​(byte[] b)
      Deprecated.
      since 3.10, use Base64 instead.
      static java.lang.String byteArrayToHexString​(byte[] b)
      Convert a byte array to a hexadecimal String.
      static java.lang.String byteToHexString​(byte b)
      Convert a byte to a hexadecimal String.
      static byte[] hexStringToByteArray​(java.lang.String s)
      Parses the supplied String into a byte[] - assumes that the text is in hex format.
      • Methods inherited from class java.lang.Object

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

      • byteToHexString

        public static java.lang.String byteToHexString​(byte b)
        Convert a byte to a hexadecimal String.
        Parameters:
        b - a single byte
        Returns:
        the hex String
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] b)
        Convert a byte array to a hexadecimal String.
        Parameters:
        b - the bytes
        Returns:
        the hex String
      • byteArrayToBase64String

        @Deprecated
        public static java.lang.String byteArrayToBase64String​(byte[] b)
        Deprecated.
        since 3.10, use Base64 instead.
        Convert a byte array to a base 64 string (see RFC 1421).
        Parameters:
        b - the bytes
        Returns:
        the String
      • base64StringToByteArray

        @Deprecated
        public static byte[] base64StringToByteArray​(java.lang.String s)
        Deprecated.
        since 3.10, use Base64 instead.
        Convert a base 64 string to a byte array (see RFC 1421).
        Parameters:
        s - the string
        Returns:
        the byte array
        Throws:
        java.lang.NumberFormatException - if the stirng is invalid base64
      • hexStringToByteArray

        public static byte[] hexStringToByteArray​(java.lang.String s)
                                           throws java.io.IOException
        Parses the supplied String into a byte[] - assumes that the text is in hex format.
        Parameters:
        s - the hex String
        Returns:
        the byte array.
        Throws:
        java.io.IOException