Module java.base
Package java.util

Class Base64


  • public classBase64extendsObject
    This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme. The implementation of this class supports the following types of Base64 as specified inRFC 4648 andRFC 2045.
    • Basic

      Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.

    • URL and Filename safe

      Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.

    • MIME

      Uses "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded output must be represented in lines of no more than 76 characters each and uses a carriage return'\r' followed immediately by a linefeed'\n' as the line separator. No line separator is added to the end of the encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in decoding operation.

    Unless otherwise noted, passing anull argument to a method of this class will cause aNullPointerException to be thrown.

    Since:
    1.8
    • Method Detail

      • getMimeEncoder

        public static Base64.Encoder getMimeEncoder()
        Returns aBase64.Encoder that encodes using theMIME type base64 encoding scheme.
        Returns:
        A Base64 encoder.
      • getMimeEncoder

        public static Base64.Encoder getMimeEncoder​(int lineLength,                                            byte[] lineSeparator)
        Returns aBase64.Encoder that encodes using theMIME type base64 encoding scheme with specified line length and line separators.
        Parameters:
        lineLength - the length of each output line (rounded down to nearest multiple of 4). If the rounded down line length is not a positive value, the output will not be separated in lines
        lineSeparator - the line separator for each output line
        Returns:
        A Base64 encoder.
        Throws:
        IllegalArgumentException - iflineSeparator includes any character of "The Base64 Alphabet" as specified in Table 1 of RFC 2045.
      • getMimeDecoder

        public static Base64.Decoder getMimeDecoder()
        Returns aBase64.Decoder that decodes using theMIME type base64 decoding scheme.
        Returns:
        A Base64 decoder.