Class DecoderUtil


  • public class DecoderUtil
    extends Object
    Static methods for decoding strings, byte arrays and encoded words.
    • Constructor Detail

      • DecoderUtil

        public DecoderUtil()
    • Method Detail

      • decodeEncodedWords

        public static String decodeEncodedWords​(String body,
                                                DecodeMonitor monitor)
                                         throws IllegalArgumentException
        Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64.
        Parameters:
        body - the string to decode
        monitor - the DecodeMonitor to be used.
        Returns:
        the decoded string.
        Throws:
        IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
      • decodeEncodedWords

        public static String decodeEncodedWords​(String body,
                                                Charset fallback)
                                         throws IllegalArgumentException
        Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid.
        Parameters:
        body - the string to decode
        fallback - the fallback Charset to be used.
        Returns:
        the decoded string.
        Throws:
        IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
      • decodeEncodedWords

        public static String decodeEncodedWords​(String body,
                                                DecodeMonitor monitor,
                                                Charset fallback)
                                         throws IllegalArgumentException
        Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid.
        Parameters:
        body - the string to decode
        monitor - the DecodeMonitor to be used.
        fallback - the fallback Charset to be used.
        Returns:
        the decoded string.
        Throws:
        IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
      • decodeEncodedWords

        public static String decodeEncodedWords​(String body,
                                                DecodeMonitor monitor,
                                                Charset fallback,
                                                Map<Charset,​Charset> charsetOverrides)
                                         throws IllegalArgumentException
        Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid. Additionally, the found charset will be overridden if a corresponding mapping is found.
        Parameters:
        body - the string to decode
        monitor - the DecodeMonitor to be used.
        fallback - the fallback Charset to be used.
        charsetOverrides - the Charsets to override and their replacements. Must not be null.
        Returns:
        the decoded string.
        Throws:
        IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)