Class Base64


  • public class Base64
    extends Object
    Base64 encoding util class.
    • Constructor Detail

      • Base64

        public Base64()
    • Method Detail

      • encode

        public static String encode​(byte[] data)
        Converts a byte array into a Base64 encoded string.
        Parameters:
        data - bytes to encode.
        Returns:
        base64 encoding of data; 4 chars for every 3 bytes.
      • encode

        public static String encode​(byte[] data,
                                    int offset,
                                    int length)
        Converts a byte array into a Base64 encoded string.
        Parameters:
        data - bytes to encode.
        offset - which byte to start at.
        length - how many bytes to encode; padding will be added if needed.
        Returns:
        base64 encoding of data; 4 chars for every 3 bytes.
      • decode

        public static byte[] decode​(String encoded)
                             throws IOException
        Converts a Base64 encoded string to a byte array.
        Parameters:
        encoded - Base64 encoded data.
        Returns:
        decode binary data; 3 bytes for every 4 chars - minus padding.
        Throws:
        IOException - if an I/O error occurs reading the data.
      • decode

        public static byte[] decode​(String encoded,
                                    int offset,
                                    int length)
                             throws IOException
        Converts an embedded Base64 encoded string to a byte array.
        Parameters:
        encoded - a String with Base64 data embedded in it.
        offset - which char of the String to start at.
        length - how many chars to decode; must be a multiple of 4.
        Returns:
        decode binary data; 3 bytes for every 4 chars - minus padding.
        Throws:
        IOException - if an I/O error occurs reading the data.