Class Base64Coder


  • public class Base64Coder
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Base64Coder.CharMap  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(char[] in)
      Decodes a byte array from Base64 format.
      static byte[] decode​(char[] in, byte[] inverseCharMap)  
      static byte[] decode​(char[] in, int iOff, int iLen, byte[] inverseCharMap)
      Decodes a byte array from Base64 format.
      static byte[] decode​(char[] in, int iOff, int iLen, Base64Coder.CharMap inverseCharMap)  
      static byte[] decode​(char[] in, Base64Coder.CharMap inverseCharMap)  
      static byte[] decode​(java.lang.String s)
      Decodes a byte array from Base64 format.
      static byte[] decode​(java.lang.String s, Base64Coder.CharMap inverseCharMap)
      Decodes a byte array from Base64 format.
      static byte[] decodeLines​(java.lang.String s)  
      static byte[] decodeLines​(java.lang.String s, byte[] inverseCharMap)
      Decodes a byte array from Base64 format and ignores line separators, tabs and blanks.
      static byte[] decodeLines​(java.lang.String s, Base64Coder.CharMap inverseCharMap)  
      static java.lang.String decodeString​(java.lang.String s)
      Decodes a string from Base64 format.
      static java.lang.String decodeString​(java.lang.String s, boolean useUrlSafeEncoding)  
      static char[] encode​(byte[] in)
      Encodes a byte array into Base64 format.
      static char[] encode​(byte[] in, char[] charMap)  
      static char[] encode​(byte[] in, int iLen)
      Encodes a byte array into Base64 format.
      static char[] encode​(byte[] in, int iOff, int iLen, char[] charMap)
      Encodes a byte array into Base64 format.
      static char[] encode​(byte[] in, int iOff, int iLen, Base64Coder.CharMap charMap)  
      static char[] encode​(byte[] in, Base64Coder.CharMap charMap)  
      static java.lang.String encodeLines​(byte[] in)
      Encodes a byte array into Base64 format and breaks the output into lines of 76 characters.
      static java.lang.String encodeLines​(byte[] in, int iOff, int iLen, int lineLen, java.lang.String lineSeparator, char[] charMap)
      Encodes a byte array into Base64 format and breaks the output into lines.
      static java.lang.String encodeLines​(byte[] in, int iOff, int iLen, int lineLen, java.lang.String lineSeparator, Base64Coder.CharMap charMap)  
      static java.lang.String encodeString​(java.lang.String s)
      Encodes a string into Base64 format.
      static java.lang.String encodeString​(java.lang.String s, boolean useUrlsafeEncoding)
      Encodes a string into Base64 format, optionally using URL-safe encoding instead of the "regular" Base64 encoding.
      • Methods inherited from class java.lang.Object

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

      • encodeString

        public static java.lang.String encodeString​(java.lang.String s)
        Encodes a string into Base64 format. No blanks or line breaks are inserted.
        Parameters:
        s - A String to be encoded.
        Returns:
        A String containing the Base64 encoded data.
      • encodeString

        public static java.lang.String encodeString​(java.lang.String s,
                                                    boolean useUrlsafeEncoding)
        Encodes a string into Base64 format, optionally using URL-safe encoding instead of the "regular" Base64 encoding. No blanks or line breaks are inserted.
        Parameters:
        s - A String to be encoded.
        useUrlsafeEncoding - If true, this encodes the result with an alternate URL-safe set of characters.
        Returns:
        A String containing the Base64 encoded data.
      • encodeLines

        public static java.lang.String encodeLines​(byte[] in)
        Encodes a byte array into Base64 format and breaks the output into lines of 76 characters. This method is compatible with sun.misc.BASE64Encoder.encodeBuffer(byte[]).
        Parameters:
        in - An array containing the data bytes to be encoded.
        Returns:
        A String containing the Base64 encoded data, broken into lines.
      • encodeLines

        public static java.lang.String encodeLines​(byte[] in,
                                                   int iOff,
                                                   int iLen,
                                                   int lineLen,
                                                   java.lang.String lineSeparator,
                                                   Base64Coder.CharMap charMap)
      • encodeLines

        public static java.lang.String encodeLines​(byte[] in,
                                                   int iOff,
                                                   int iLen,
                                                   int lineLen,
                                                   java.lang.String lineSeparator,
                                                   char[] charMap)
        Encodes a byte array into Base64 format and breaks the output into lines.
        Parameters:
        in - An array containing the data bytes to be encoded.
        iOff - Offset of the first byte in in to be processed.
        iLen - Number of bytes to be processed in in, starting at iOff.
        lineLen - Line length for the output data. Should be a multiple of 4.
        lineSeparator - The line separator to be used to separate the output lines.
        charMap - char map to use
        Returns:
        A String containing the Base64 encoded data, broken into lines.
      • encode

        public static char[] encode​(byte[] in)
        Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
        Parameters:
        in - An array containing the data bytes to be encoded.
        Returns:
        A character array containing the Base64 encoded data.
      • encode

        public static char[] encode​(byte[] in,
                                    char[] charMap)
      • encode

        public static char[] encode​(byte[] in,
                                    int iLen)
        Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
        Parameters:
        in - An array containing the data bytes to be encoded.
        iLen - Number of bytes to process in in.
        Returns:
        A character array containing the Base64 encoded data.
      • encode

        public static char[] encode​(byte[] in,
                                    int iOff,
                                    int iLen,
                                    Base64Coder.CharMap charMap)
      • encode

        public static char[] encode​(byte[] in,
                                    int iOff,
                                    int iLen,
                                    char[] charMap)
        Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
        Parameters:
        in - An array containing the data bytes to be encoded.
        iOff - Offset of the first byte in in to be processed.
        iLen - Number of bytes to process in in, starting at iOff.
        charMap - char map to use
        Returns:
        A character array containing the Base64 encoded data.
      • decodeString

        public static java.lang.String decodeString​(java.lang.String s)
        Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
        Parameters:
        s - A Base64 String to be decoded.
        Returns:
        A String containing the decoded data.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.
      • decodeString

        public static java.lang.String decodeString​(java.lang.String s,
                                                    boolean useUrlSafeEncoding)
      • decodeLines

        public static byte[] decodeLines​(java.lang.String s)
      • decodeLines

        public static byte[] decodeLines​(java.lang.String s,
                                         Base64Coder.CharMap inverseCharMap)
      • decodeLines

        public static byte[] decodeLines​(java.lang.String s,
                                         byte[] inverseCharMap)
        Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space characters are ignored in the input data. This method is compatible with sun.misc.BASE64Decoder.decodeBuffer(String).
        Parameters:
        s - A Base64 String to be decoded.
        inverseCharMap -
        Returns:
        An array containing the decoded data bytes.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.
      • decode

        public static byte[] decode​(java.lang.String s)
        Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
        Parameters:
        s - A Base64 String to be decoded.
        Returns:
        An array containing the decoded data bytes.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.
      • decode

        public static byte[] decode​(java.lang.String s,
                                    Base64Coder.CharMap inverseCharMap)
        Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
        Parameters:
        s - A Base64 String to be decoded.
        inverseCharMap -
        Returns:
        An array containing the decoded data bytes.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.
      • decode

        public static byte[] decode​(char[] in,
                                    byte[] inverseCharMap)
      • decode

        public static byte[] decode​(char[] in)
        Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
        Parameters:
        in - A character array containing the Base64 encoded data.
        Returns:
        An array containing the decoded data bytes.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.
      • decode

        public static byte[] decode​(char[] in,
                                    int iOff,
                                    int iLen,
                                    Base64Coder.CharMap inverseCharMap)
      • decode

        public static byte[] decode​(char[] in,
                                    int iOff,
                                    int iLen,
                                    byte[] inverseCharMap)
        Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
        Parameters:
        in - A character array containing the Base64 encoded data.
        iOff - Offset of the first character in in to be processed.
        iLen - Number of characters to process in in, starting at iOff.
        inverseCharMap - charMap to use
        Returns:
        An array containing the decoded data bytes.
        Throws:
        java.lang.IllegalArgumentException - If the input is not valid Base64 encoded data.