本文整理汇总了Java中org.apache.james.mime4j.util.CharsetUtil类的典型用法代码示例。如果您正苦于以下问题:Java CharsetUtil类的具体用法?Java CharsetUtil怎么用?Java CharsetUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharsetUtil类属于org.apache.james.mime4j.util包,在下文中一共展示了CharsetUtil类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: determineCharset
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
private static Charset determineCharset(String text) {
// it is an important property of iso-8859-1 that it directly maps
// unicode code points 0000 to 00ff to byte values 00 to ff.
boolean ascii = true;
final int len = text.length();
for (int index = 0; index < len; index++) {
char ch = text.charAt(index);
if (ch > 0xff) {
return CharsetUtil.UTF_8;
}
if (ch > 0x7f) {
ascii = false;
}
}
return ascii ? CharsetUtil.US_ASCII : CharsetUtil.ISO_8859_1;
}
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:17,代码来源:EncoderUtil.java
示例2: getCharset
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
protected Charset getCharset() {
Entity e = getParent();
ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
Field.CONTENT_TYPE);
Charset charset = null;
switch (this.mode) {
case STRICT:
charset = MIME.DEFAULT_CHARSET;
break;
case BROWSER_COMPATIBLE:
if (cField.getCharset() != null) {
charset = CharsetUtil.getCharset(cField.getCharset());
} else {
charset = CharsetUtil.getCharset(HTTP.DEFAULT_CONTENT_CHARSET);
}
break;
}
return charset;
}
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:21,代码来源:HttpMultipart.java
示例3: defaultObject
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
@Override
protected Recipient defaultObject(String completionText) {
Address[] parsedAddresses = Address.parse(completionText);
if (!CharsetUtil.isASCII(completionText)) {
setError(getContext().getString(R.string.recipient_error_non_ascii));
return null;
}
if (parsedAddresses.length == 0 || parsedAddresses[0].getAddress() == null) {
setError(getContext().getString(R.string.recipient_error_parse_failed));
return null;
}
return new Recipient(parsedAddresses[0]);
}
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:15,代码来源:RecipientSelectView.java
示例4: 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;
}
开发者ID:ram-sharma-6453,项目名称:email-mime-parser,代码行数:50,代码来源:MimeWordDecoder.java
示例5: writeTo
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
/**
* Write the Header to the given OutputStream.
* <p>
* Compatibility mode:
* <ul>
* <li>
* {@link MessageUtils#LENIENT}: use charset of the Content-Type header
* </li>
* <li>
* {@link MessageUtils#STRICT_ERROR}: use US-ASCII and throw {@link MimeException}
* if a non ASCII character is encountered
* </li>
* <li>
* {@link MessageUtils#STRICT_ERROR}: ignore non ASCII characters if encountered
* </li>
* </ul>
* @param out the OutputStream to write to
* @param mode compatibility mode:
* {@link MessageUtils#LENIENT}, {@link MessageUtils#STRICT_ERROR}, {@link MessageUtils#STRICT_IGNORE}
*
* @throws IOException if case of an I/O error
* @throws MimeException if case of a MIME protocol violation
*/
public void writeTo(final OutputStream out, int mode) throws IOException, MimeException {
Charset charset = null;
if (mode == MessageUtils.LENIENT) {
final ContentTypeField contentTypeField = ((ContentTypeField) getField(Field.CONTENT_TYPE));
if (contentTypeField == null) {
charset = MessageUtils.DEFAULT_CHARSET;
} else {
final String contentTypeFieldCharset = contentTypeField.getCharset();
if (contentTypeField != null && contentTypeFieldCharset != null) {
charset = CharsetUtil.getCharset(contentTypeFieldCharset);
} else {
charset = MessageUtils.ISO_8859_1;
}
}
} else {
charset = MessageUtils.DEFAULT_CHARSET;
}
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(out, charset), 8192);
for (Iterator it = fields.iterator(); it.hasNext();) {
Field field = (Field) it.next();
String fs = field.toString();
if (mode == MessageUtils.STRICT_ERROR && !MessageUtils.isASCII(fs)) {
throw new MimeException("Header '" + fs + "' violates RFC 822");
}
writer.write(fs);
writer.write(MessageUtils.CRLF);
}
writer.write(MessageUtils.CRLF);
writer.flush();
}
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:55,代码来源:Header.java
示例6: getReader
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
/**
* @see org.apache.james.mime4j.message.TextBody#getReader()
*/
public Reader getReader() throws UnsupportedEncodingException, IOException {
String javaCharset = null;
if (mimeCharset != null) {
javaCharset = CharsetUtil.toJavaCharset(mimeCharset);
}
if (javaCharset == null) {
javaCharset = "ISO-8859-1";
}
return new InputStreamReader(tempFile.getInputStream(), javaCharset);
}
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:16,代码来源:TempFileTextBody.java
示例7: 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;
}
}
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:72,代码来源:DecoderUtil.java
示例8: decodeContentDisposition
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
private static ContentDispositionHeaderValue decodeContentDisposition(
String headerValue) throws MimeException {
ContentDispositionHeaderValue contentDispositionHeaderValue = new ContentDispositionHeaderValue();
contentDispositionHeaderValue.setValue(headerValue);
try {
int i = headerValue.indexOf('\'');
if (i <= 0) {
if (decodeParametersStrict) {
throw new MimeException(
"Missing charset in encoded value: " + headerValue);
}
return contentDispositionHeaderValue;
}
String charset = headerValue.substring(0, i);
charset = Common.getFallbackCharset(charset);
if (CharsetUtil.lookup(charset) == null) {
return contentDispositionHeaderValue;
}
int li = headerValue.indexOf('\'', i + 1);
if (li < 0) {
if (decodeParametersStrict) {
throw new MimeException(
"Missing language in encoded value: " + headerValue);
}
return contentDispositionHeaderValue;
}
headerValue = headerValue.substring(li + 1);
contentDispositionHeaderValue.setCharset(charset);
contentDispositionHeaderValue.setValue(decodeBytes(headerValue, charset));
} catch (NumberFormatException nex) {
if (decodeParametersStrict) {
throw new MimeException(nex);
}
} catch (StringIndexOutOfBoundsException ex) {
if (decodeParametersStrict) {
throw new MimeException(ex);
}
}
return contentDispositionHeaderValue;
}
开发者ID:ram-sharma-6453,项目名称:email-mime-parser,代码行数:43,代码来源:ContentDispositionDecoder.java
示例9: 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;
}
}
开发者ID:daxslab,项目名称:daxSmail,代码行数:72,代码来源:DecoderUtil.java
示例10: writeTo
import org.apache.james.mime4j.util.CharsetUtil; //导入依赖的package包/类
/**
* Write the Multipart to the given OutputStream.
*
* @param out the OutputStream to write to
* @param mode compatibility mode
*
* @throws IOException if case of an I/O error
* @throws MimeException if case of a MIME protocol violation
*/
public void writeTo(final OutputStream out, int mode) throws IOException, MimeException {
Entity e = getParent();
ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
Field.CONTENT_TYPE);
if (cField == null || cField.getBoundary() == null) {
throw new MimeException("Multipart boundary not specified");
}
String boundary = cField.getBoundary();
Charset charset = null;
if (mode == MessageUtils.LENIENT) {
if (cField != null && cField.getCharset() != null) {
charset = CharsetUtil.getCharset(cField.getCharset());
} else {
charset = MessageUtils.ISO_8859_1;
}
} else {
charset = MessageUtils.DEFAULT_CHARSET;
}
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(out, charset), 8192);
List bodyParts = getBodyParts();
writer.write(getPreamble());
writer.write(MessageUtils.CRLF);
for (int i = 0; i < bodyParts.size(); i++) {
writer.write("--");
writer.write(boundary);
writer.write(MessageUtils.CRLF);
writer.flush();
final BodyPart bodyPart = (BodyPart) bodyParts.get(i);
bodyPart.writeTo(out, mode);
writer.write(MessageUtils.CRLF);
}
writer.write("--");
writer.write(boundary);
writer.write("--");
writer.write(MessageUtils.CRLF);
final String epilogue = getEpilogue();
writer.write(epilogue);
writer.flush();
}
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:57,代码来源:Multipart.java
注:本文中的org.apache.james.mime4j.util.CharsetUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论