public class EncoderUtil
extends java.lang.Object
Description:
Title:首亨软件 - TSS/CRM等
限定符和类型 | 类和说明 |
---|---|
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.
|
限定符和类型 | 方法和说明 |
---|---|
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 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 boolean |
hasToBeEncoded(java.lang.String text,
int usedCharacters)
Determines if the specified string has to encoded into an encoded-word.
|
static boolean |
isToken(java.lang.String str)
Tests whether the specified string is a token as defined in RFC 2045
section 5.1.
|
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).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 boolean isToken(java.lang.String str)
str
- string to test.true
if the specified string is a RFC 2045 token,
false
otherwise.