Class Base64


  • public class Base64
    extends java.lang.Object
    Contains methods to encode and decode to base 64. The base 64 format is used to convert binaries into text so that they can be sent over a stream. It may then be converted back to binary form.

    Note that 3 bytes base 16 (hexadecimal) are encoded into 4 bytes base 64, so the final length is 33% bigger.

    Since:
    SuperWaba 5.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int[] toBase10
      Convertion table from base 64 to base 10
      static char[] toBase64
      Convertion table from base 10 to base 64
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int decode​(byte[] src, int srcStart, int srcLength, byte[] dest, int destStart)
      Decodes a given base 64 data into a base 10 data.
      Important: error detection is NOT made, so you must be sure that no invalid characters are given!
      Important: it does not check if the destiny has the proper size
      static byte[] decode​(java.lang.String inStr)
      Decodes the given string into a byte array with the exact size.
      static void decode​(ByteArrayStream in, ByteArrayStream out)
      Decodes a given base 64 stream into a base 10 stream.
      Important: error detection is NOT made, so you must be sure that no invalid characters are given!
      static java.lang.String encode​(byte[] bytes)
      Encodes the given byte array and returns a base 64 generated string.
      static byte[] encode​(byte[] bytes, int count)
      Encodes the given byte array and returns a base 64 generated byte array.
      static java.lang.String encode​(byte[] bytes, int start, int count)
      Encodes the given byte array and returns a base 64 generated string.
      static void encode​(ByteArrayStream in, ByteArrayStream out)
      Encodes a given base 10 stream into a base 64 stream.
      • Methods inherited from class java.lang.Object

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

      • toBase64

        public static final char[] toBase64
        Convertion table from base 10 to base 64
      • toBase10

        public static int[] toBase10
        Convertion table from base 64 to base 10
    • Constructor Detail

      • Base64

        public Base64()
    • Method Detail

      • decode

        public static void decode​(ByteArrayStream in,
                                  ByteArrayStream out)
        Decodes a given base 64 stream into a base 10 stream.
        Important: error detection is NOT made, so you must be sure that no invalid characters are given!
        Parameters:
        in - The base 64 input stream. Its position must be set to the current size of the input data.
        out - The base 10 output stream. When returning, its position will be set with the output size in bytes.
      • decode

        public static int decode​(byte[] src,
                                 int srcStart,
                                 int srcLength,
                                 byte[] dest,
                                 int destStart)
        Decodes a given base 64 data into a base 10 data.
        Important: error detection is NOT made, so you must be sure that no invalid characters are given!
        Important: it does not check if the destiny has the proper size
        Parameters:
        src - The base 64 input data.
        dest - The base 10 output data.
        srcStart - First position from the source
        srcLength - How many bytes should be read?
        destStart - First position to be written in the destiny
        Returns:
        The amount of bytes written in the destiny
      • decode

        public static byte[] decode​(java.lang.String inStr)
        Decodes the given string into a byte array with the exact size.
        Parameters:
        inStr - The input string in base 64.
      • encode

        public static java.lang.String encode​(byte[] bytes)
        Encodes the given byte array and returns a base 64 generated string.
        Parameters:
        bytes - The base 10 byte array to be encoded into base 64.
      • encode

        public static java.lang.String encode​(byte[] bytes,
                                              int start,
                                              int count)
        Encodes the given byte array and returns a base 64 generated string.
        Parameters:
        bytes - The base 10 byte array to be encoded into base 64.
        start - The start position in the array.
        count - The number of bytes to encode.
        Returns:
        The encoded string.
        Since:
        TotalCross 1.13
      • encode

        public static byte[] encode​(byte[] bytes,
                                    int count)
        Encodes the given byte array and returns a base 64 generated byte array.
        Parameters:
        bytes - The base 10 byte array to be encoded into base 64.
        Returns:
        The base 64 byte array.
      • encode

        public static void encode​(ByteArrayStream in,
                                  ByteArrayStream out)
        Encodes a given base 10 stream into a base 64 stream.
        Parameters:
        in - The Base 10 intput stream. Its position must be set to the current size of the input data.
        out - The Base 64 ouput stream. When returning, its position will be set with the output size in bytes.