Class Base64


  • public class Base64
    extends java.lang.Object

    A class for encoding and decoding to and from Base64. Also contains Binary identifiers which are used to indicate what type a message is when transferred in Base64. This is done by adding a one byte prefix to the start of the encoded message.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char BYTE
      The binary indentifier for a byte.
      static char DOUBLE
      The binary indentifier for a double.
      static char FLOAT
      The binary indentifier for a float.
      static char INT
      The binary indentifier for a int.
      static char LONG
      The binary indentifier for a lgon.
      static char OPAQUE
      The binary indentifier for an opaque type.
      static char SHORT
      The binary indentifier for a short.
      static char STRING
      The binary indentifier for a string.
      static char U_BYTE
      The binary indentifier for an unsigned byte.
      static char U_INT
      The binary indentifier for an unsigned int.
      static char U_LONG
      The binary indentifier for an unsigned long.
      static char U_SHORT
      The binary indentifier for an unsigned short.
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] encode​(byte b)
      Base64 encodes a byte value.
      static byte[] encode​(byte[] bytes)
      Base64 encodes an opaque type.
      static byte[] encode​(double d)
      Base64 encodes a double value.
      static byte[] encode​(float f)
      Base64 encodes a float value.
      static byte[] encode​(int i)
      Base64 encodes an int value.
      static byte[] encode​(long l)
      Base64 encodes a long value.
      static byte[] encode​(short s)
      Base64 encodes a short value.
      static byte getByte​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a byte value.
      static double getDouble​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a double value.
      static float getFloat​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a float value.
      static int getInt​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into an int value.
      static long getLong​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a long value.
      static byte[] getOpaque​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into an opaque value.
      static short getShort​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a short value.
      static java.lang.String getString​(java.lang.String str)
      Decodes a Base64 encoded String and converts it into a String value.
      • Methods inherited from class java.lang.Object

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

      • FLOAT

        public static final char FLOAT

        The binary indentifier for a float.

        See Also:
        Constant Field Values
      • DOUBLE

        public static final char DOUBLE

        The binary indentifier for a double.

        See Also:
        Constant Field Values
      • SHORT

        public static final char SHORT

        The binary indentifier for a short.

        See Also:
        Constant Field Values
      • U_BYTE

        public static final char U_BYTE

        The binary indentifier for an unsigned byte.

        See Also:
        Constant Field Values
      • U_SHORT

        public static final char U_SHORT

        The binary indentifier for an unsigned short.

        See Also:
        Constant Field Values
      • U_INT

        public static final char U_INT

        The binary indentifier for an unsigned int.

        See Also:
        Constant Field Values
      • U_LONG

        public static final char U_LONG

        The binary indentifier for an unsigned long.

        See Also:
        Constant Field Values
      • STRING

        public static final char STRING

        The binary indentifier for a string.

        See Also:
        Constant Field Values
      • OPAQUE

        public static final char OPAQUE

        The binary indentifier for an opaque type.

        See Also:
        Constant Field Values
    • Constructor Detail

      • Base64

        public Base64()
    • Method Detail

      • getDouble

        public static double getDouble​(java.lang.String str)
                                throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a double value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded double value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getFloat

        public static float getFloat​(java.lang.String str)
                              throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a float value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded float value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getByte

        public static byte getByte​(java.lang.String str)
                            throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a byte value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded byte value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getShort

        public static short getShort​(java.lang.String str)
                              throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a short value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded short value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getInt

        public static int getInt​(java.lang.String str)
                          throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into an int value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded int value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getLong

        public static long getLong​(java.lang.String str)
                            throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a long value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded long value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getString

        public static java.lang.String getString​(java.lang.String str)
                                          throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into a String value.

        Parameters:
        str - the string to be decoded.
        Returns:
        the decoded String value.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • getOpaque

        public static byte[] getOpaque​(java.lang.String str)
                                throws InvalidBase64DataException

        Decodes a Base64 encoded String and converts it into an opaque value.

        Parameters:
        str - the string to be decoded.
        Returns:
        a Base64 decoded byte array.
        Throws:
        InvalidBase64DataException - if the String was incomplete.
      • encode

        public static byte[] encode​(byte b)

        Base64 encodes a byte value.

        Parameters:
        b - the byte to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(short s)

        Base64 encodes a short value.

        Parameters:
        s - the short to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(int i)

        Base64 encodes an int value.

        Parameters:
        i - the int to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(long l)

        Base64 encodes a long value.

        Parameters:
        l - the long to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(double d)

        Base64 encodes a double value.

        Parameters:
        d - the double to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(float f)

        Base64 encodes a float value.

        Parameters:
        f - the float to be encoded.
        Returns:
        an encoded byte array.
      • encode

        public static byte[] encode​(byte[] bytes)

        Base64 encodes an opaque type.

        Parameters:
        bytes - the opaque type to be encoded.
        Returns:
        an encoded byte array.