Class Base64

java.lang.Object
com.caplin.util.base64.Base64

public class Base64 extends 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 final char
    The binary indentifier for a byte.
    static final char
    The binary indentifier for a double.
    static final char
    The binary indentifier for a float.
    static final char
    The binary indentifier for a int.
    static final char
    The binary indentifier for a lgon.
    static final char
    The binary indentifier for an opaque type.
    static final char
    The binary indentifier for a short.
    static final char
    The binary indentifier for a string.
    static final char
    The binary indentifier for an unsigned byte.
    static final char
    The binary indentifier for an unsigned int.
    static final char
    The binary indentifier for an unsigned long.
    static final char
    The binary indentifier for an unsigned short.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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
    Decodes a Base64 encoded String and converts it into a byte value.
    static double
    Decodes a Base64 encoded String and converts it into a double value.
    static float
    Decodes a Base64 encoded String and converts it into a float value.
    static int
    Decodes a Base64 encoded String and converts it into an int value.
    static long
    Decodes a Base64 encoded String and converts it into a long value.
    static byte[]
    Decodes a Base64 encoded String and converts it into an opaque value.
    static short
    Decodes a Base64 encoded String and converts it into a short value.
    static String
    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 Details

    • FLOAT

      public static final char FLOAT

      The binary indentifier for a float.

      See Also:
    • DOUBLE

      public static final char DOUBLE

      The binary indentifier for a double.

      See Also:
    • BYTE

      public static final char BYTE

      The binary indentifier for a byte.

      See Also:
    • SHORT

      public static final char SHORT

      The binary indentifier for a short.

      See Also:
    • INT

      public static final char INT

      The binary indentifier for a int.

      See Also:
    • LONG

      public static final char LONG

      The binary indentifier for a lgon.

      See Also:
    • U_BYTE

      public static final char U_BYTE

      The binary indentifier for an unsigned byte.

      See Also:
    • U_SHORT

      public static final char U_SHORT

      The binary indentifier for an unsigned short.

      See Also:
    • U_INT

      public static final char U_INT

      The binary indentifier for an unsigned int.

      See Also:
    • U_LONG

      public static final char U_LONG

      The binary indentifier for an unsigned long.

      See Also:
    • STRING

      public static final char STRING

      The binary indentifier for a string.

      See Also:
    • OPAQUE

      public static final char OPAQUE

      The binary indentifier for an opaque type.

      See Also:
  • Constructor Details

    • Base64

      public Base64()
  • Method Details

    • getDouble

      public static double getDouble(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(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(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(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(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(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 String getString(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(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.