mimeutility.html
来自「SUN公司官方J2EE中文帮助文档 应该不错 有兴趣的下来看看 html格式的」· HTML 代码 · 共 724 行 · 第 1/3 页
HTML
724 行
The given Unicode string is examined for non US-ASCII
characters. If the string contains only US-ASCII characters,
it is returned as-is. If the string contains non US-ASCII
characters, it is first character-encoded using the specified
charset, then transfer-encoded using either the B or Q encoding.
The resulting bytes are then returned as a Unicode string
containing only ASCII characters. <p>
Note that this method should be used to encode only
"unstructured" RFC 822 headers.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - the header value<DD><CODE>charset</CODE> - the charset. If this parameter is null, the
platform's default chatset is used.<DD><CODE>encoding</CODE> - the encoding to be used. Currently supported
values are "B" and "Q". If this parameter is null, then
the "Q" encoding is used if most of characters to be
encoded are in the ASCII charset, otherwise "B" encoding
is used.<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters</DL>
</DD>
</DL>
<HR>
<A NAME="decodeText(java.lang.String)"><!-- --></A><H3>
decodeText</H3>
<PRE>
public static java.lang.String <B>decodeText</B>(java.lang.String etext)
throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Decode "unstructured" headers, that is, headers that are defined
as '*text' as per RFC 822. <p>
The string is decoded using the algorithm specified in
RFC 2047, Section 6.1.1. If the charset-conversion fails
for any sequence, an UnsupportedEncodingException is thrown.
If the String is not an RFC 2047 style encoded header, it is
returned as-is <p>
Example of usage:
<p><blockquote><pre>
MimePart part = ...
String rawvalue = null;
String value = null;
try {
if ((rawvalue = part.getHeader("X-mailer")[0]) != null)
value = MimeUtility.decodeText(rawvalue);
} catch (UnsupportedEncodingException e) {
// Don't care
value = rawvalue;
} catch (MessagingException me) { }
return value;
</pre></blockquote><p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>etext</CODE> - the possibly encoded value<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the charset
conversion failed.</DL>
</DD>
</DL>
<HR>
<A NAME="encodeWord(java.lang.String)"><!-- --></A><H3>
encodeWord</H3>
<PRE>
public static java.lang.String <B>encodeWord</B>(java.lang.String word)
throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "word" token into mail-safe form as per
RFC 2047. <p>
The given Unicode string is examined for non US-ASCII
characters. If the string contains only US-ASCII characters,
it is returned as-is. If the string contains non US-ASCII
characters, it is first character-encoded using the platform's
default charset, then transfer-encoded using either the B or
Q encoding. The resulting bytes are then returned as a Unicode
string containing only ASCII characters. <p>
This method is meant to be used when creating RFC 822 "phrases".
The InternetAddress class, for example, uses this to encode
it's 'phrase' component.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - unicode string<DT><B>Returns:</B><DD>Array of Unicode strings containing only US-ASCII
characters.<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the encoding fails</DL>
</DD>
</DL>
<HR>
<A NAME="encodeWord(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
encodeWord</H3>
<PRE>
public static java.lang.String <B>encodeWord</B>(java.lang.String word,
java.lang.String charset,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "word" token into mail-safe form as per
RFC 2047. <p>
The given Unicode string is examined for non US-ASCII
characters. If the string contains only US-ASCII characters,
it is returned as-is. If the string contains non US-ASCII
characters, it is first character-encoded using the specified
charset, then transfer-encoded using either the B or Q encoding.
The resulting bytes are then returned as a Unicode string
containing only ASCII characters. <p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - unicode string<DD><CODE>charset</CODE> - the MIME charset<DD><CODE>encoding</CODE> - the encoding to be used. Currently supported
values are "B" and "Q". If this parameter is null, then
the "Q" encoding is used if most of characters to be
encoded are in the ASCII charset, otherwise "B" encoding
is used.<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters<DT><B>Throws:</B><DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the encoding fails</DL>
</DD>
</DL>
<HR>
<A NAME="decodeWord(java.lang.String)"><!-- --></A><H3>
decodeWord</H3>
<PRE>
public static java.lang.String <B>decodeWord</B>(java.lang.String eword)
throws <A HREF="../../../javax/mail/internet/ParseException.html">ParseException</A>,
java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>The string is parsed using the rules in RFC 2047 for parsing
an "encoded-word". If the parse fails, a ParseException is
thrown. Otherwise, it is transfer-decoded, and then
charset-converted into Unicode. If the charset-conversion
fails, an UnsupportedEncodingException is thrown.<p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>eword</CODE> - the possibly encoded value<DT><B>Throws:</B><DD><CODE><A HREF="../../../javax/mail/internet/ParseException.html">ParseException</A></CODE> - if the string is not an
encoded-word as per RFC 2047.<DD><CODE>java.io.UnsupportedEncodingException</CODE> - if the charset
conversion failed.</DL>
</DD>
</DL>
<HR>
<A NAME="quote(java.lang.String, java.lang.String)"><!-- --></A><H3>
quote</H3>
<PRE>
public static java.lang.String <B>quote</B>(java.lang.String word,
java.lang.String specials)</PRE>
<DL>
<DD>A utility method to quote a word, if the word contains any
characters from the specified 'specials' list.<p>
The <code>HeaderTokenizer</code> class defines two special
sets of delimiters - MIME and RFC 822. <p>
This method is typically used during the generation of
RFC 822 and MIME header fields.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>word</CODE> - word to be quoted<DD><CODE>specials</CODE> - the set of special characters<DT><B>Returns:</B><DD>the possibly quoted word<DT><B>See Also: </B><DD><A HREF="../../../javax/mail/internet/HeaderTokenizer.html#MIME"><CODE>HeaderTokenizer.MIME</CODE></A>,
<A HREF="../../../javax/mail/internet/HeaderTokenizer.html#RFC822"><CODE>HeaderTokenizer.RFC822</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="javaCharset(java.lang.String)"><!-- --></A><H3>
javaCharset</H3>
<PRE>
public static java.lang.String <B>javaCharset</B>(java.lang.String charset)</PRE>
<DL>
<DD>Convert a MIME charset name into a valid Java charset name. <p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>charset</CODE> - the MIME charset name<DT><B>Returns:</B><DD>the Java charset equivalent. If a suitable mapping is
not available, the passed in charset is itself returned.</DL>
</DD>
</DL>
<HR>
<A NAME="mimeCharset(java.lang.String)"><!-- --></A><H3>
mimeCharset</H3>
<PRE>
public static java.lang.String <B>mimeCharset</B>(java.lang.String charset)</PRE>
<DL>
<DD>Convert a java charset into its MIME charset name. <p>
Note that a future version of JDK (post 1.2) might provide
this functionality, in which case, we may deprecate this
method then.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>charset</CODE> - the JDK charset<DT><B>Returns:</B><DD>the MIME/IANA equivalent. If a mapping
is not possible, the passed in charset itself
is returned.<DT><B>Since: </B><DD>JavaMail 1.1</DD>
</DL>
</DD>
</DL>
<HR>
<A NAME="getDefaultJavaCharset()"><!-- --></A><H3>
getDefaultJavaCharset</H3>
<PRE>
public static java.lang.String <B>getDefaultJavaCharset</B>()</PRE>
<DL>
<DD>Get the default charset corresponding to the system's current
default locale. <p><DD><DL>
<DT><B>Returns:</B><DD>the default charset of the system's default locale,
as a Java charset. (NOT a MIME charset)<DT><B>Since: </B><DD>JavaMail 1.1</DD>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../javax/mail/internet/MimePartDataSource.html"><B>PREV CLASS</B></A>
<A HREF="../../../javax/mail/internet/NewsAddress.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="MimeUtility.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?