Package org.apache.james.mime4j.codec
Class DecoderUtil
- java.lang.Object
-
- org.apache.james.mime4j.codec.DecoderUtil
-
public class DecoderUtil extends java.lang.Object
Static methods for decoding strings, byte arrays and encoded words.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>>
_recyclerRef
-
Constructor Summary
Constructors Constructor Description DecoderUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.String
decodeB(java.lang.String encodedText, java.lang.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(java.lang.String s, DecodeMonitor monitor)
Decodes a string containing base64 encoded data.(package private) static java.lang.String
decodeEncodedWords(java.lang.String body)
static java.lang.String
decodeEncodedWords(java.lang.String body, java.nio.charset.Charset fallback)
Decodes a string containing encoded words as defined by RFC 2047.static java.lang.String
decodeEncodedWords(java.lang.String body, DecodeMonitor monitor)
Decodes a string containing encoded words as defined by RFC 2047.static java.lang.String
decodeEncodedWords(java.lang.String body, DecodeMonitor monitor, java.nio.charset.Charset fallback)
Decodes a string containing encoded words as defined by RFC 2047.static java.lang.String
decodeEncodedWords(java.lang.String body, DecodeMonitor monitor, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides)
Decodes a string containing encoded words as defined by RFC 2047.(package private) static java.lang.String
decodeQ(java.lang.String encodedText, java.lang.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(java.lang.String s, DecodeMonitor monitor)
Decodes a string containing quoted-printable encoded data.static BufferRecycler
getBufferRecycler()
private static java.nio.charset.Charset
lookupCharset(java.lang.String mimeCharset, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides)
private static void
monitor(DecodeMonitor monitor, java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText, java.lang.String dropDesc, java.lang.String... strings)
private static java.lang.String
recombine(java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText)
private static java.lang.String
replaceUnderscores(java.lang.String str)
private static java.lang.String
tryDecodeEncodedWord(java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText, DecodeMonitor monitor, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides)
-
-
-
Field Detail
-
_recyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>> _recyclerRef
-
-
Method Detail
-
getBufferRecycler
public static BufferRecycler getBufferRecycler()
-
decodeQuotedPrintable
private static byte[] decodeQuotedPrintable(java.lang.String s, DecodeMonitor monitor)
Decodes a string containing quoted-printable encoded data.- Parameters:
s
- the string to decode.- Returns:
- the decoded bytes.
-
decodeBase64
private static byte[] decodeBase64(java.lang.String s, DecodeMonitor monitor)
Decodes a string containing base64 encoded data.- Parameters:
s
- the string to decode.monitor
-- Returns:
- the decoded bytes.
-
decodeB
static java.lang.String decodeB(java.lang.String encodedText, java.lang.String charset, DecodeMonitor monitor) throws java.io.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:
java.io.UnsupportedEncodingException
- if the given Java charset isn't supported.
-
decodeQ
static java.lang.String decodeQ(java.lang.String encodedText, java.lang.String charset, DecodeMonitor monitor) throws java.io.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:
java.io.UnsupportedEncodingException
- if the given Java charset isn't supported.
-
decodeEncodedWords
static java.lang.String decodeEncodedWords(java.lang.String body)
-
decodeEncodedWords
public static java.lang.String decodeEncodedWords(java.lang.String body, DecodeMonitor monitor) throws java.lang.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:
java.lang.IllegalArgumentException
- only if the DecodeMonitor strategy throws it (Strict parsing)
-
decodeEncodedWords
public static java.lang.String decodeEncodedWords(java.lang.String body, java.nio.charset.Charset fallback) throws java.lang.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:
java.lang.IllegalArgumentException
- only if the DecodeMonitor strategy throws it (Strict parsing)
-
decodeEncodedWords
public static java.lang.String decodeEncodedWords(java.lang.String body, DecodeMonitor monitor, java.nio.charset.Charset fallback) throws java.lang.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:
java.lang.IllegalArgumentException
- only if the DecodeMonitor strategy throws it (Strict parsing)
-
decodeEncodedWords
public static java.lang.String decodeEncodedWords(java.lang.String body, DecodeMonitor monitor, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides) throws java.lang.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 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:
java.lang.IllegalArgumentException
- only if the DecodeMonitor strategy throws it (Strict parsing)
-
tryDecodeEncodedWord
private static java.lang.String tryDecodeEncodedWord(java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText, DecodeMonitor monitor, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides)
-
lookupCharset
private static java.nio.charset.Charset lookupCharset(java.lang.String mimeCharset, java.nio.charset.Charset fallback, java.util.Map<java.nio.charset.Charset,java.nio.charset.Charset> charsetOverrides)
-
monitor
private static void monitor(DecodeMonitor monitor, java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText, java.lang.String dropDesc, java.lang.String... strings) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
recombine
private static java.lang.String recombine(java.lang.String mimeCharset, java.lang.String encoding, java.lang.String encodedText)
-
replaceUnderscores
private static java.lang.String replaceUnderscores(java.lang.String str)
-
-