mimeutility.html
来自「SUN的JAVA MAIL API」· HTML 代码 · 共 677 行 · 第 1/2 页
HTML
677 行
If the primary type of this datasource is not "text", then if
all the bytes of its input stream are US-ASCII, the encoding
is "7bit". If there is even one non-US-ASCII character, the
encoding is "base64".
</ul><DD><DL>
<DT><B>Parameters:</B><DD><CODE>ds</CODE> - DataSource<DT><B>Returns:</B><DD>the encoding. This is either "7bit",
"quoted-printable" or "base64"</DL>
</DD>
</DL>
<HR>
<A NAME="decode(java.io.InputStream, java.lang.String)"><!-- --></A><H3>
decode</H3>
<PRE>
public static java.io.InputStream <B>decode</B>(java.io.InputStream is,
java.lang.String encoding)
throws <A HREF="../../../javax/mail/MessagingException.html">MessagingException</A></PRE>
<DL>
<DD>Decode the given input stream. The Input stream returned is
the decoded input stream. All the encodings defined in RFC 2045
are supported here. They include "base64", "quoted-printable",
"7bit", "8bit", and "binary". In addition, "uuencode" is also
supported.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>is</CODE> - input stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DT><B>Returns:</B><DD>decoded input stream.</DL>
</DD>
</DL>
<HR>
<A NAME="encode(java.io.OutputStream, java.lang.String)"><!-- --></A><H3>
encode</H3>
<PRE>
public static java.io.OutputStream <B>encode</B>(java.io.OutputStream os,
java.lang.String encoding)
throws <A HREF="../../../javax/mail/MessagingException.html">MessagingException</A></PRE>
<DL>
<DD>Wrap an encoder around the given output stream.
All the encodings defined in RFC 2045 are supported here.
They include "base64", "quoted-printable", "7bit", "8bit" and
"binary". In addition, "uuencode" is also supported.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>os</CODE> - output stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DT><B>Returns:</B><DD>output stream that applies the
specified encoding.</DL>
</DD>
</DL>
<HR>
<A NAME="encodeText(java.lang.String)"><!-- --></A><H3>
encodeText</H3>
<PRE>
public static java.lang.String <B>encodeText</B>(java.lang.String text)
throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "text" 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>
Note that this method should be used to encode only
"unstructured" RFC 822 headers. <p>
Example of usage:
<p><blockquote><pre>
MimePart part = ...
String rawvalue = "FooBar Mailer, Japanese version 1.1"
try {
// If we know for sure that rawvalue contains only US-ASCII
// characters, we can skip the encoding part
part.setHeader("X-mailer", MimeUtility.encodeText(rawvalue));
} catch (UnsupportedEncodingException e) {
// encoding failure
} catch (MessagingException me) {
// setHeader() failure
}
</pre></blockquote><p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>text</CODE> - unicode string<DT><B>Returns:</B><DD>Unicode string containing only US-ASCII characters<DT><B>Throws:</B><DD>java.io.UnsupportedEncodingException - if the encoding fails</DL>
</DD>
</DL>
<HR>
<A NAME="encodeText(java.lang.String, java.lang.String, java.lang.String)"><!-- --></A><H3>
encodeText</H3>
<PRE>
public static java.lang.String <B>encodeText</B>(java.lang.String text,
java.lang.String charset,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "text" 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>
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>java.io.UnsupportedEncodingException - 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>java.io.UnsupportedEncodingException - 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>java.io.UnsupportedEncodingException - 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><A HREF="../../../javax/mail/internet/ParseException.html">ParseException</A> - if the string is not an
encoded-word as per RFC 2047.<DD>java.io.UnsupportedEncodingException - 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" ID="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT ID="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-summary.html"><FONT ID="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" ID="NavBarCell1Rev"> <FONT ID="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="class-use/MimeUtility.html"><FONT ID="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="package-tree.html"><FONT ID="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT ID="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT ID="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" ID="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT ID="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" ID="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" ID="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" ID="NavBarCell3"><FONT SIZE="-2">
SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" ID="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 + -
显示快捷键?