本文整理汇总了Java中org.apache.james.mime4j.util.CharsetUtil.isWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetUtil.isWhitespace方法的具体用法?Java CharsetUtil.isWhitespace怎么用?Java CharsetUtil.isWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.james.mime4j.util.CharsetUtil
的用法示例。
在下文中一共展示了CharsetUtil.isWhitespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeEncodedWords
import org.apache.james.mime4j.util.CharsetUtil; //导入方法依赖的package包/类
/**
* 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.
*
* @param body the string to decode
* @param monitor the DecodeMonitor to be used.
* @return the decoded string.
* @throws IllegalArgumentException only if the DecodeMonitor strategy throws it (Strict parsing)
*/
public static String decodeEncodedWords(String body, DecodeMonitor monitor) throws IllegalArgumentException {
if(body != null && !body.isEmpty()){
int tailIndex = 0;
boolean lastMatchValid = false;
StringBuilder sb = new StringBuilder();
for (Matcher matcher = PATTERN_ENCODED_WORD.matcher(body); matcher.find();) {
String separator = matcher.group(1);
String mimeCharset = matcher.group(2);
String encoding = matcher.group(3);
String encodedText = matcher.group(4);
mimeCharset = Common.getFallbackCharset(mimeCharset);
String decoded = null;
decoded = tryDecodeEncodedWord(mimeCharset, encoding, encodedText, monitor);
if (decoded == null) {
sb.append(matcher.group(0));
} else {
if (!lastMatchValid || !CharsetUtil.isWhitespace(separator)) {
sb.append(separator);
}
sb.append(decoded);
}
tailIndex = matcher.end();
lastMatchValid = decoded != null;
}
if (tailIndex == 0) {
return body;
} else {
sb.append(body.substring(tailIndex));
return sb.toString();
}
}
return body;
}
示例2: decodeEncodedWords
import org.apache.james.mime4j.util.CharsetUtil; //导入方法依赖的package包/类
/**
* Decodes a string containing encoded words as defined by RFC 2047.
* Encoded words in have the form
* =?charset?enc?Encoded word?= where enc is either 'Q' or 'q' for
* quoted-printable and 'B' or 'b' for Base64.
*
* ANDROID: COPIED FROM A NEWER VERSION OF MIME4J
*
* @param body the string to decode.
* @param message the message which has the string.
* @return the decoded string.
*/
public static String decodeEncodedWords(String body, Message message) {
// ANDROID: Most strings will not include "=?" so a quick test can prevent unneeded
// object creation. This could also be handled via lazy creation of the StringBuilder.
if (!body.contains("=?")) {
return body;
}
int previousEnd = 0;
boolean previousWasEncoded = false;
StringBuilder sb = new StringBuilder();
while (true) {
int begin = body.indexOf("=?", previousEnd);
if (begin == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
// ANDROID: The mime4j original version has an error here. It gets confused if
// the encoded string begins with an '=' (just after "?Q?"). This patch seeks forward
// to find the two '?' in the "header", before looking for the final "?=".
int qm1 = body.indexOf('?', begin + 2);
if (qm1 == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
int qm2 = body.indexOf('?', qm1 + 1);
if (qm2 == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
int end = body.indexOf("?=", qm2 + 1);
if (end == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
end += 2;
String sep = body.substring(previousEnd, begin);
String decoded = decodeEncodedWord(body, begin, end, message);
if (decoded == null) {
sb.append(sep);
sb.append(body.substring(begin, end));
} else {
if (!previousWasEncoded || !CharsetUtil.isWhitespace(sep)) {
sb.append(sep);
}
sb.append(decoded);
}
previousEnd = end;
previousWasEncoded = decoded != null;
}
}
示例3: decodeEncodedWords
import org.apache.james.mime4j.util.CharsetUtil; //导入方法依赖的package包/类
/**
* Decodes a string containing encoded words as defined by RFC 2047.
* Encoded words in have the form
* =?charset?enc?Encoded word?= where enc is either 'Q' or 'q' for
* quoted-printable and 'B' or 'b' for Base64.
*
* ANDROID: COPIED FROM A NEWER VERSION OF MIME4J
*
* @param body the string to decode.
* @param message the message which has the string.
* @return the decoded string.
*/
public static String decodeEncodedWords(String body, Message message) {
// ANDROID: Most strings will not include "=?" so a quick test can prevent unneeded
// object creation. This could also be handled via lazy creation of the StringBuilder.
if (body.indexOf("=?") == -1) {
return body;
}
int previousEnd = 0;
boolean previousWasEncoded = false;
StringBuilder sb = new StringBuilder();
while (true) {
int begin = body.indexOf("=?", previousEnd);
if (begin == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
// ANDROID: The mime4j original version has an error here. It gets confused if
// the encoded string begins with an '=' (just after "?Q?"). This patch seeks forward
// to find the two '?' in the "header", before looking for the final "?=".
int qm1 = body.indexOf('?', begin + 2);
if (qm1 == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
int qm2 = body.indexOf('?', qm1 + 1);
if (qm2 == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
int end = body.indexOf("?=", qm2 + 1);
if (end == -1) {
sb.append(body.substring(previousEnd));
return sb.toString();
}
end += 2;
String sep = body.substring(previousEnd, begin);
String decoded = decodeEncodedWord(body, begin, end, message);
if (decoded == null) {
sb.append(sep);
sb.append(body.substring(begin, end));
} else {
if (!previousWasEncoded || !CharsetUtil.isWhitespace(sep)) {
sb.append(sep);
}
sb.append(decoded);
}
previousEnd = end;
previousWasEncoded = decoded != null;
}
}