public class EncoderUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
EncoderUtil.Encoding
Selects one of the two encodings specified in RFC 2047.
|
static class |
EncoderUtil.Usage
Indicates the intended usage of an encoded word.
|
| Modifier and Type | Field and Description |
|---|---|
private static java.util.BitSet |
ATEXT_CHARS |
private static char |
BASE64_PAD |
private static byte[] |
BASE64_TABLE |
private static java.lang.String |
ENC_WORD_PREFIX |
private static java.lang.String |
ENC_WORD_SUFFIX |
private static int |
ENCODED_WORD_MAX_LENGTH |
private static int |
MAX_USED_CHARACTERS |
private static java.util.BitSet |
Q_REGULAR_CHARS |
private static java.util.BitSet |
Q_RESTRICTED_CHARS |
private static java.util.BitSet |
TOKEN_CHARS |
| Modifier | Constructor and Description |
|---|---|
private |
EncoderUtil() |
| Modifier and Type | Method and Description |
|---|---|
private static int |
bEncodedLength(byte[] bytes) |
private static java.nio.charset.Charset |
determineCharset(java.lang.String text) |
private static EncoderUtil.Encoding |
determineEncoding(byte[] bytes,
EncoderUtil.Usage usage) |
private static byte[] |
encode(java.lang.String text,
java.nio.charset.Charset charset) |
static java.lang.String |
encodeAddressDisplayName(java.lang.String displayName)
Encodes the display-name portion of an address.
|
static java.lang.String |
encodeAddressLocalPart(java.lang.String localPart)
Encodes the local part of an address specification as described in RFC
5322 section 3.4.1.
|
static java.lang.String |
encodeB(byte[] bytes)
Encodes the specified byte array using the B encoding defined in RFC
2047.
|
static void |
encodeB(java.io.InputStream in,
java.io.OutputStream out)
Encodes the given stream using base64.
|
private static java.lang.String |
encodeB(java.lang.String prefix,
java.lang.String text,
int usedCharacters,
java.nio.charset.Charset charset,
byte[] bytes) |
static java.lang.String |
encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage)
Encodes the specified text into an encoded word or a sequence of encoded
words separated by space.
|
static java.lang.String |
encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters)
Encodes the specified text into an encoded word or a sequence of encoded
words separated by space.
|
static java.lang.String |
encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters,
java.nio.charset.Charset charset,
EncoderUtil.Encoding encoding)
Encodes the specified text into an encoded word or a sequence of encoded
words separated by space.
|
static java.lang.String |
encodeHeaderParameter(java.lang.String name,
java.lang.String value)
Encodes the specified strings into a header parameter as described in RFC
2045 section 5.1 and RFC 2183 section 2.
|
static java.lang.String |
encodeIfNecessary(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters)
Shortcut method that encodes the specified text into an encoded-word if
the text has to be encoded.
|
static java.lang.String |
encodeQ(byte[] bytes,
EncoderUtil.Usage usage)
Encodes the specified byte array using the Q encoding defined in RFC
2047.
|
static void |
encodeQ(java.io.InputStream in,
java.io.OutputStream out)
Encodes the given stream using Quoted-Printable.
|
private static java.lang.String |
encodeQ(java.lang.String prefix,
java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters,
java.nio.charset.Charset charset,
byte[] bytes) |
static void |
encodeQBinary(java.io.InputStream in,
java.io.OutputStream out)
Encodes the given stream using Quoted-Printable.
|
static boolean |
hasToBeEncoded(java.lang.String text,
int usedCharacters)
Determines if the specified string has to encoded into an encoded-word.
|
private static char |
hexDigit(int i) |
private static java.util.BitSet |
initChars(java.lang.String specials) |
private static boolean |
isAtomPhrase(java.lang.String str) |
private static boolean |
isDotAtomText(java.lang.String str) |
static boolean |
isToken(java.lang.String str)
Tests whether the specified string is a token as defined in RFC 2045
section 5.1.
|
private static int |
qEncodedLength(byte[] bytes,
EncoderUtil.Usage usage) |
private static java.lang.String |
quote(java.lang.String str) |
private static final byte[] BASE64_TABLE
private static final char BASE64_PAD
private static final java.util.BitSet Q_REGULAR_CHARS
private static final java.util.BitSet Q_RESTRICTED_CHARS
private static final int MAX_USED_CHARACTERS
private static final java.lang.String ENC_WORD_PREFIX
private static final java.lang.String ENC_WORD_SUFFIX
private static final int ENCODED_WORD_MAX_LENGTH
private static final java.util.BitSet TOKEN_CHARS
private static final java.util.BitSet ATEXT_CHARS
private static java.util.BitSet initChars(java.lang.String specials)
public static java.lang.String encodeAddressDisplayName(java.lang.String displayName)
displayName - display-name to encode.public static java.lang.String encodeAddressLocalPart(java.lang.String localPart)
localPart - the local part to encodepublic static java.lang.String encodeHeaderParameter(java.lang.String name,
java.lang.String value)
name - parameter name.value - parameter value.public static java.lang.String encodeIfNecessary(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters)
text - text to encode.usage - whether the encoded-word is to be used to replace a text token
or a word entity (see RFC 822).usedCharacters - number of characters already used up (0 <= usedCharacters <= 50).public static boolean hasToBeEncoded(java.lang.String text,
int usedCharacters)
true if the text contains characters that don't
fall into the printable ASCII character set or if the text contains a
'word' (sequence of non-whitespace characters) longer than 77 characters
(including characters already used up in the line).text - text to analyze.usedCharacters - number of characters already used up (0 <= usedCharacters <= 50).true if the specified text has to be encoded into
an encoded-word, false otherwise.public static java.lang.String encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage)
The charset to encode the specified text into a byte array and the encoding to use for the encoded-word are detected automatically.
This method assumes that zero characters have already been used up in the current line.
text - text to encode.usage - whether the encoded-word is to be used to replace a text token
or a word entity (see RFC 822).hasToBeEncoded(String, int)public static java.lang.String encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters)
The charset to encode the specified text into a byte array and the encoding to use for the encoded-word are detected automatically.
text - text to encode.usage - whether the encoded-word is to be used to replace a text token
or a word entity (see RFC 822).usedCharacters - number of characters already used up (0 <= usedCharacters <= 50).hasToBeEncoded(String, int)public static java.lang.String encodeEncodedWord(java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters,
java.nio.charset.Charset charset,
EncoderUtil.Encoding encoding)
text - text to encode.usage - whether the encoded-word is to be used to replace a text token
or a word entity (see RFC 822).usedCharacters - number of characters already used up (0 <= usedCharacters <= 50).charset - the Java charset that should be used to encode the specified
string into a byte array. A suitable charset is detected
automatically if this parameter is null.encoding - the encoding to use for the encoded-word (either B or Q). A
suitable encoding is automatically chosen if this parameter is
null.hasToBeEncoded(String, int)public static java.lang.String encodeB(byte[] bytes)
bytes - byte array to encode.public static java.lang.String encodeQ(byte[] bytes,
EncoderUtil.Usage usage)
bytes - byte array to encode.usage - whether the encoded-word is to be used to replace a text token
or a word entity (see RFC 822).public static void encodeQBinary(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - not nullout - not nulljava.io.IOExceptionpublic static void encodeQ(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - not nullout - not nulljava.io.IOExceptionpublic static void encodeB(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - not nullout - not nulljava.io.IOException - if an I/O error occurspublic static boolean isToken(java.lang.String str)
str - string to test.true if the specified string is a RFC 2045 token,
false otherwise.private static boolean isAtomPhrase(java.lang.String str)
private static boolean isDotAtomText(java.lang.String str)
private static java.lang.String quote(java.lang.String str)
private static java.lang.String encodeB(java.lang.String prefix,
java.lang.String text,
int usedCharacters,
java.nio.charset.Charset charset,
byte[] bytes)
private static int bEncodedLength(byte[] bytes)
private static java.lang.String encodeQ(java.lang.String prefix,
java.lang.String text,
EncoderUtil.Usage usage,
int usedCharacters,
java.nio.charset.Charset charset,
byte[] bytes)
private static int qEncodedLength(byte[] bytes,
EncoderUtil.Usage usage)
private static byte[] encode(java.lang.String text,
java.nio.charset.Charset charset)
private static java.nio.charset.Charset determineCharset(java.lang.String text)
private static EncoderUtil.Encoding determineEncoding(byte[] bytes, EncoderUtil.Usage usage)
private static char hexDigit(int i)