Package org.apache.james.mime4j.codec
Class DecoderUtil
java.lang.Object
org.apache.james.mime4j.codec.DecoderUtil
Static methods for decoding strings, byte arrays and encoded words.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal
<SoftReference<BufferRecycler>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static String
decodeB
(String encodedText, String charset, DecodeMonitor monitor) Decodes an encoded text encoded with the 'B' encoding (described in RFC 2047) found in a header field body.private static byte[]
decodeBase64
(String s, DecodeMonitor monitor) Decodes a string containing base64 encoded data.(package private) static String
decodeEncodedWords
(String body) static String
decodeEncodedWords
(String body, Charset fallback) Decodes a string containing encoded words as defined by RFC 2047.static String
decodeEncodedWords
(String body, DecodeMonitor monitor) Decodes a string containing encoded words as defined by RFC 2047.static String
decodeEncodedWords
(String body, DecodeMonitor monitor, Charset fallback) Decodes a string containing encoded words as defined by RFC 2047.static String
decodeEncodedWords
(String body, DecodeMonitor monitor, Charset fallback, Map<Charset, Charset> charsetOverrides) Decodes a string containing encoded words as defined by RFC 2047.(package private) static String
decodeQ
(String encodedText, String charset, DecodeMonitor monitor) Decodes an encoded text encoded with the 'Q' encoding (described in RFC 2047) found in a header field body.private static byte[]
decodeQuotedPrintable
(String s, DecodeMonitor monitor) Decodes a string containing quoted-printable encoded data.static BufferRecycler
private static Charset
private static void
monitor
(DecodeMonitor monitor, String mimeCharset, String encoding, String encodedText, String dropDesc, String... strings) private static String
private static String
replaceUnderscores
(String str) private static String
tryDecodeEncodedWord
(String mimeCharset, String encoding, String encodedText, DecodeMonitor monitor, Charset fallback, Map<Charset, Charset> charsetOverrides)
-
Field Details
-
_recyclerRef
-
-
Constructor Details
-
DecoderUtil
public DecoderUtil()
-
-
Method Details
-
getBufferRecycler
-
decodeQuotedPrintable
Decodes a string containing quoted-printable encoded data.- Parameters:
s
- the string to decode.- Returns:
- the decoded bytes.
-
decodeBase64
Decodes a string containing base64 encoded data.- Parameters:
s
- the string to decode.monitor
-- Returns:
- the decoded bytes.
-
decodeB
static String decodeB(String encodedText, String charset, DecodeMonitor monitor) throws UnsupportedEncodingException Decodes an encoded text encoded with the 'B' encoding (described in RFC 2047) found in a header field body.- Parameters:
encodedText
- the encoded text to decode.charset
- the Java charset to use.monitor
-- Returns:
- the decoded string.
- Throws:
UnsupportedEncodingException
- if the given Java charset isn't supported.
-
decodeQ
static String decodeQ(String encodedText, String charset, DecodeMonitor monitor) throws UnsupportedEncodingException Decodes an encoded text encoded with the 'Q' encoding (described in RFC 2047) found in a header field body.- Parameters:
encodedText
- the encoded text to decode.charset
- the Java charset to use.- Returns:
- the decoded string.
- Throws:
UnsupportedEncodingException
- if the given Java charset isn't supported.
-
decodeEncodedWords
-
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 decodemonitor
- 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 decodefallback
- 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 decodemonitor
- 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 IllegalArgumentExceptionDecodes 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 decodemonitor
- 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)
-
tryDecodeEncodedWord
-
lookupCharset
-
monitor
private static void monitor(DecodeMonitor monitor, String mimeCharset, String encoding, String encodedText, String dropDesc, String... strings) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
recombine
-
replaceUnderscores
-