Class Base64


  • public class Base64
    extends java.lang.Object
    A Base64 en/decoder. You can use it to encode and decode strings and byte arrays.
    Author:
    Tim Roes
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(java.lang.String in)
      Decode a base64 encoded string to a byte array.
      static java.lang.String decodeAsString​(java.lang.String in)
      Decode a base64 encoded string to a string.
      static java.lang.String encode​(byte[] in)
      Encode a byte array and return the encoded string.
      static java.lang.String encode​(java.lang.Byte[] in)
      Encode a Byte array and return the encoded string.
      static java.lang.String encode​(java.lang.String in)
      Encode a String and return the encoded string.
      static byte[] encodeAsBytes​(byte[] inArray)
      Encode a byte array and return the encoded byte array.
      static byte[] encodeAsBytes​(java.lang.String in)
      Encode a String and return the encoded byte array.
      • Methods inherited from class java.lang.Object

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

      • Base64

        public Base64()
    • Method Detail

      • decode

        public static byte[] decode​(java.lang.String in)
        Decode a base64 encoded string to a byte array.
        Parameters:
        in - A string representing a base64 encoding.
        Returns:
        The decoded byte array.
      • decodeAsString

        public static java.lang.String decodeAsString​(java.lang.String in)
        Decode a base64 encoded string to a string.
        Parameters:
        in - The string representation of the base64 encoding.
        Returns:
        The decoded string in the default charset of the JVM.
      • encode

        public static java.lang.String encode​(java.lang.String in)
        Encode a String and return the encoded string.
        Parameters:
        in - A string to encode.
        Returns:
        The encoded byte array.
      • encode

        public static java.lang.String encode​(java.lang.Byte[] in)
        Encode a Byte array and return the encoded string.
        Parameters:
        in - A string to encode.
        Returns:
        The encoded byte array.
      • encode

        public static java.lang.String encode​(byte[] in)
        Encode a byte array and return the encoded string.
        Parameters:
        in - A string to encode.
        Returns:
        The encoded byte array.
      • encodeAsBytes

        public static byte[] encodeAsBytes​(java.lang.String in)
        Encode a String and return the encoded byte array. Bytes that has been appended to pad the string to a multiple of four are set to -1 in the array.
        Parameters:
        in - A string to encode.
        Returns:
        The encoded byte array.
      • encodeAsBytes

        public static byte[] encodeAsBytes​(byte[] inArray)
        Encode a byte array and return the encoded byte array. Bytes that has been appended to pad the string to a multiple of four are set to -1 in the array.
        Parameters:
        inArray - A string to encode.
        Returns:
        The encoded byte array.