mimeutility.html

来自「SUN公司官方J2EE中文帮助文档 应该不错 有兴趣的下来看看 html格式的」· HTML 代码 · 共 724 行 · 第 1/3 页

HTML
724
字号
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataHandler)">getEncoding</A></B>(<A HREF="../../../javax/activation/DataHandler.html">DataHandler</A>&nbsp;dh)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Same as <code>getEncoding(DataSource)</code> except that instead
 of reading the data from an <code>InputStream</code> it uses the
 <code>writeTo</code> method to examine the data.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#getEncoding(javax.activation.DataSource)">getEncoding</A></B>(<A HREF="../../../javax/activation/DataSource.html">DataSource</A>&nbsp;ds)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the content-transfer-encoding that should be applied
 to the input stream of this datasource, to make it mailsafe.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#javaCharset(java.lang.String)">javaCharset</A></B>(java.lang.String&nbsp;charset)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a MIME charset name into a valid Java charset name.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#mimeCharset(java.lang.String)">mimeCharset</A></B>(java.lang.String&nbsp;charset)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Convert a java charset into its MIME charset name.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/mail/internet/MimeUtility.html#quote(java.lang.String, java.lang.String)">quote</A></B>(java.lang.String&nbsp;word,
      java.lang.String&nbsp;specials)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A utility method to quote a word, if the word contains any
 characters from the specified 'specials' list.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from class java.lang.Object</B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ FIELD DETAIL =========== -->

<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Field Detail</B></FONT></TD>
</TR>
</TABLE>

<A NAME="ALL"><!-- --></A><H3>
ALL</H3>
<PRE>
public static final int <B>ALL</B></PRE>
<DL>
</DL>

<!-- ========= CONSTRUCTOR DETAIL ======== -->


<!-- ============ METHOD DETAIL ========== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>

<A NAME="getEncoding(javax.activation.DataSource)"><!-- --></A><H3>
getEncoding</H3>
<PRE>
public static java.lang.String <B>getEncoding</B>(<A HREF="../../../javax/activation/DataSource.html">DataSource</A>&nbsp;ds)</PRE>
<DL>
<DD>Get the content-transfer-encoding that should be applied
 to the input stream of this datasource, to make it mailsafe. <p>

 The algorithm used here is: <br>
 <ul>
 <li>
 If the primary type of this datasource is "text" and if all
 the bytes in its input stream are US-ASCII, then the encoding
 is "7bit". If more than half of the bytes are non-US-ASCII, then
 the encoding is "base64". If less than half of the bytes are
 non-US-ASCII, then the encoding is "quoted-printable".
 <li>
 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="getEncoding(javax.activation.DataHandler)"><!-- --></A><H3>
getEncoding</H3>
<PRE>
public static java.lang.String <B>getEncoding</B>(<A HREF="../../../javax/activation/DataHandler.html">DataHandler</A>&nbsp;dh)</PRE>
<DL>
<DD>Same as <code>getEncoding(DataSource)</code> except that instead
 of reading the data from an <code>InputStream</code> it uses the
 <code>writeTo</code> method to examine the data.  This is more
 efficient in the common case of a <code>DataHandler</code>
 created with an object and a MIME type (for example, a
 "text/plain" String) because all the I/O is done in this
 thread.  In the case requiring an <code>InputStream</code> the
 <code>DataHandler</code> uses a thread, a pair of pipe streams,
 and the <code>writeTo</code> method to produce the data. <p><DD><DL>
<DT><B>Since: </B><DD>JavaMail 1.2</DD>
</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&nbsp;is,
                                         java.lang.String&nbsp;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&nbsp;os,
                                          java.lang.String&nbsp;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="encode(java.io.OutputStream, java.lang.String, java.lang.String)"><!-- --></A><H3>
encode</H3>
<PRE>
public static java.io.OutputStream <B>encode</B>(java.io.OutputStream&nbsp;os,
                                          java.lang.String&nbsp;encoding,
                                          java.lang.String&nbsp;filename)
                                   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.
 The <code>filename</code> parameter is used with the "uuencode"
 encoding and is included in the encoded output.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>os</CODE> - output stream<DD><CODE>encoding</CODE> - the encoding of the stream.<DD><CODE>filename</CODE> - name for the file being encoded (only used
                          with uuencode)<DT><B>Returns:</B><DD>output stream that applies the
                          specified encoding.<DT><B>Since: </B><DD>JavaMail 1.2</DD>
</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&nbsp;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><CODE>java.io.UnsupportedEncodingException</CODE> - 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&nbsp;text,
                                          java.lang.String&nbsp;charset,
                                          java.lang.String&nbsp;encoding)
                                   throws java.io.UnsupportedEncodingException</PRE>
<DL>
<DD>Encode a RFC 822 "text" token into mail-safe form as per
 RFC 2047. <p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?