|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.mail Interface Part
- All Known Subinterfaces:
- MimePart
- All Known Implementing Classes:
- BodyPart, Message, MimeBodyPart, MimeMessage, PreencodedMimeBodyPart
public interface Part
Part
接口是 Message 和 BodyPart 的公共基本接口。 Part 由一个属性集和一个 "Content" 组成。
属性:
JavaMail API 定义了一组标准 Part 属性,这些属性通用于大多数现有 Mail 系统。这些属性有自己的设置方法和获取方法。Mail 系统可能还支持其他 Part 属性,这些属性是以名称-值对的形式表示的,其中名称和值都是 String。
内容:
"content" 的数据类型由 getContentType()
方法返回。MIME 类型系统用于指定数据类型。
Part 的 "content" 有多种格式:
- 作为 DataHandler - 使用
getDataHandler()
方法。Part 的 "content" 还可通过javax.activation.DataHandler
对象获取。DataHandler 对象允许客户端发现可以对内容进行的操作,并实例化相应的组件来执行这些操作。 - 作为输入流 - 使用
getInputStream()
方法。所有特定于邮件的编码都是在返回此流之前解码的。 - 作为 Java 对象 - 使用
getContent()
方法。此方法以 Java 对象的形式返回 "content"。返回的对象无疑取决于内容本身。需要特别指出的是,"multipart" Part 的内容总是 Multipart 或其子类。也就是说,对 "multipart" 类型的 Part 调用getContent()
将总是返回 Multipart(或子类)对象。
writeTo()
方法,该方法以适用于传输的、对邮件安全的形式传出字节流。此字节流通常是 Part 属性及其内容的字节流的聚合。 Message 和 BodyPart 实现 Part 接口。注意,在 MIME 用法中,Part 将模拟 Entity(RFC 2045 的第 2.4 节)。
The Part
interface is the common base interface for
Messages and BodyParts.
Part consists of a set of attributes and a "Content".
Attributes:
The JavaMail API defines a set of standard Part attributes that are considered to be common to most existing Mail systems. These attributes have their own settor and gettor methods. Mail systems may support other Part attributes as well, these are represented as name-value pairs where both the name and value are Strings.
Content:
The data type of the "content" is returned by
the getContentType()
method. The MIME typing system
is used to name data types.
The "content" of a Part is available in various formats:
- As a DataHandler - using the
getDataHandler()
method. The "content" of a Part is also available through ajavax.activation.DataHandler
object. The DataHandler object allows clients to discover the operations available on the content, and to instantiate the appropriate component to perform those operations. - As an input stream - using the
getInputStream()
method. Any mail-specific encodings are decoded before this stream is returned. - As a Java object - using the
getContent()
method. This method returns the "content" as a Java object. The returned object is of course dependent on the content itself. In particular, a "multipart" Part's content is always a Multipart or subclass thereof. That is,getContent()
on a "multipart" type Part will always return a Multipart (or subclass) object.
writeTo()
method that streams
out its bytestream in mail-safe form suitable for transmission.
This bytestream is typically an aggregation of the Part attributes
and its content's bytestream. Message and BodyPart implement the Part interface. Note that in MIME parlance, Part models an Entity (RFC 2045, Section 2.4).
- Author:
- John Mani
Field Summary | |
---|---|
static String |
ATTACHMENT
This part should be presented as an attachment. |
static String |
INLINE
This part should be presented inline. |
Method Summary | |
---|---|
void |
addHeader(String header_name,
String header_value)
Add this value to the existing values for this header_name. |
Enumeration |
getAllHeaders()
Return all the headers from this part as an Enumeration of Header objects. |
Object |
getContent()
Return the content as a Java object. |
String |
getContentType()
Returns the Content-Type of the content of this part. |
DataHandler |
getDataHandler()
Return a DataHandler for the content within this part. |
String |
getDescription()
Return a description String for this part. |
String |
getDisposition()
Return the disposition of this part. |
String |
getFileName()
Get the filename associated with this part, if possible. |
String[] |
getHeader(String header_name)
Get all the headers for this header name. |
InputStream |
getInputStream()
Return an input stream for this part's "content". |
int |
getLineCount()
Return the number of lines in the content of this part. |
Enumeration |
getMatchingHeaders(String[] header_names)
Return matching headers from this part as an Enumeration of Header objects. |
Enumeration |
getNonMatchingHeaders(String[] header_names)
Return non-matching headers from this envelope as an Enumeration of Header objects. |
int |
getSize()
Return the size of the content of this part in bytes. |
boolean |
isMimeType(String mimeType)
Is this Part of the specified MIME type? |
void |
removeHeader(String header_name)
Remove all headers with this name. |
void |
setContent(Multipart mp)
This method sets the given Multipart object as this message's content. |
void |
setContent(Object obj,
String type)
A convenience method for setting this part's content. |
void |
setDataHandler(DataHandler dh)
This method provides the mechanism to set this part's content. |
void |
setDescription(String description)
Set a description String for this part. |
void |
setDisposition(String disposition)
Set the disposition of this part. |
void |
setFileName(String filename)
Set the filename associated with this part, if possible. |
void |
setHeader(String header_name,
String header_value)
Set the value for this header_name. |
void |
setText(String text)
A convenience method that sets the given String as this part's content with a MIME type of "text/plain". |
void |
writeTo(OutputStream os)
Output a bytestream for this Part. |
Field Detail |
---|
英文文档:
ATTACHMENT
static final String ATTACHMENT
- This part should be presented as an attachment.
英文文档:
INLINE
static final String INLINE
- This part should be presented inline.
Method Detail |
---|
public int
getSize() throws MessagingException
返回此部分的内容大小(以字节为单位)。如果无法确定大小,则返回 -1。
注意,该大小可能不是内容大小的准确度量,可能没有考虑内容的传输编码。该大小适合显示在用户界面中,为用户提供此部分的大小的粗略参考。
return | 内容大小(以字节为单位) |
Throws | MessagingException: |
getSize
int getSize() throws MessagingException
- Return the size of the content of this part in bytes.
Return -1 if the size cannot be determined.
Note that the size may not be an exact measure of the content size and may or may not account for any transfer encoding of the content. The size is appropriate for display in a user interface to give the user a rough idea of the size of this part.
- Returns:
- size of content in bytes
- Throws:
MessagingException
public int
getLineCount() throws MessagingException
返回此部分的内容的行数。如果无法确定该数值,则返回 -1。
注意,此数值可能不是内容长度的准确度量,可能没有考虑内容的传输编码。
return | 内容的行数。 |
Throws | MessagingException: |
getLineCount
int getLineCount() throws MessagingException
- Return the number of lines in the content of this part.
Return -1 if the number cannot be determined.
Note that this number may not be an exact measure of the
content length and may or may not account for any transfer
encoding of the content.
- Returns:
- number of lines in the content.
- Throws:
MessagingException
public String
getContentType() throws MessagingException
返回此部分的内容的 Content-Type。如果 Content-Type 无法确定,则返回 null。
MIME 类型系统用于指定 Content-type。
return | 此部分的 ContentType |
Throws | MessagingException: |
See also | javax.activation.DataHandler |
getContentType
String getContentType() throws MessagingException
- Returns the Content-Type of the content of this part.
Returns null if the Content-Type could not be determined.
The MIME typing system is used to name Content-types.
- Returns:
- The ContentType of this part
- Throws:
MessagingException
- See Also:
DataHandler
public boolean
isMimeType(String mimeType) throws MessagingException
此 Part 是指定的 MIME 类型吗?此方法仅比较 primaryType
和 subType
。忽略内容类型参数。
例如,当比较内容类型的 "text/plain" 部分与 "text/plain; charset=foobar" 时,此方法将返回 true
。
如果 mimeType
的 subType
是特殊字符 '*',则比较过程中将忽略 subtype。
isMimeType
boolean isMimeType(String mimeType) throws MessagingException
- Is this Part of the specified MIME type? This method
compares only the
primaryType
andsubType
. The parameters of the content types are ignored.For example, this method will return
true
when comparing a Part of content type "text/plain" with "text/plain; charset=foobar".If the
subType
ofmimeType
is the special character '*', then the subtype is ignored during the comparison. - Throws:
MessagingException
public String
getDisposition() throws MessagingException
返回此部分的 disposition。disposition 描述各部分应该如何展示给用户。(请参见 RFC 2183。)返回值应该不考虑大小写。例如:
String disp = part.getDisposition(); if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) // treat as attachment if not first part
return | 此部分的 disposition;如果未知,则返回 null |
Throws | MessagingException: |
See also | ATTACHMENT, INLINE, getFileName |
getDisposition
String getDisposition() throws MessagingException
- Return the disposition of this part. The disposition
describes how the part should be presented to the user.
(See RFC 2183.) The return value should be considered
without regard to case. For example:
String disp = part.getDisposition(); if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) // treat as attachment if not first part
- Returns:
- disposition of this part, or null if unknown
- Throws:
MessagingException
- See Also:
ATTACHMENT
,INLINE
,getFileName()
public void
setDisposition(String disposition) throws MessagingException
设置此部分的 disposition。
disposition | 此部分的 disposition |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改此头 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
See also | ATTACHMENT, INLINE, setFileName |
setDisposition
void setDisposition(String disposition) throws MessagingException
- Set the disposition of this part.
- Parameters:
disposition
- disposition of this part- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of this headerIllegalStateException
- if this Part is obtained from a READ_ONLY folder- See Also:
ATTACHMENT
,INLINE
,setFileName(java.lang.String)
public String
getDescription() throws MessagingException
返回此部分的描述 String。这通常包括一些与此部分关联的描述性信息。如果不存在,则返回 null。
return | 此部分的描述 |
Throws | MessagingException: |
getDescription
String getDescription() throws MessagingException
- Return a description String for this part. This typically
associates some descriptive information with this part.
Returns null if none is available.
- Returns:
- description of this part
- Throws:
MessagingException
public void
setDescription(String description) throws MessagingException
设置此部分的描述 String。这通常包括一些与此部分关联的描述性信息。
description | 此部分的描述 |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改此头 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setDescription
void setDescription(String description) throws MessagingException
- Set a description String for this part. This typically
associates some descriptive information with this part.
- Parameters:
description
- description of this part- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of this headerIllegalStateException
- if this Part is obtained from a READ_ONLY folder
public String
getFileName() throws MessagingException
如果可能,获取与此部分关联的文件名称。在此部分表示从文件加载的“附件”时非常有用。该文件名通常是一个简单名称,不包含目录组件。
return | 与此部分关联的文件名称 |
getFileName
String getFileName() throws MessagingException
- Get the filename associated with this part, if possible.
Useful if this part represents an "attachment" that was
loaded from a file. The filename will usually be a simple
name, not including directory components.
- Returns:
- Filename to associate with this part
- Throws:
MessagingException
public void
setFileName(String filename) throws MessagingException
如果可能,设置与此部分关联的文件名称。在此部分表示从文件加载的“附件”时非常有用。该文件名通常是一个简单名称,不包含目录组件。
filename | 与此部分关联的文件名称 |
Throws | IllegalWriteException: 如果底层实现不支持修改此头 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setFileName
void setFileName(String filename) throws MessagingException
- Set the filename associated with this part, if possible.
Useful if this part represents an "attachment" that was
loaded from a file. The filename will usually be a simple
name, not including directory components.
- Parameters:
filename
- Filename to associate with this part- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of this headerIllegalStateException
- if this Part is obtained from a READ_ONLY folderMessagingException
public java.io.InputStream
getInputStream() throws java.io.IOException, MessagingException
返回用于此部分的 "content" 的输入流。所有特定于邮件的传输编码都将在提供输入流之前解码。
这通常是一个便捷方法,该方法只调用 DataHandler 的 getInputStream()
方法。
return | InputStream |
Throws | java.io.IOException: 此异常通常由 DataHandler 抛出。有关更多信息,请参考 javax.activation.DataHandler 的文档。 |
Throws | MessagingException: |
See also | getDataHandler, getInputStream |
getInputStream
InputStream getInputStream() throws IOException, MessagingException
- Return an input stream for this part's "content". Any
mail-specific transfer encodings will be decoded before the
input stream is provided.
This is typically a convenience method that just invokes the DataHandler's
getInputStream()
method. - Returns:
- an InputStream
- Throws:
IOException
- this is typically thrown by the DataHandler. Refer to the documentation for javax.activation.DataHandler for more details.MessagingException
- See Also:
getDataHandler()
,DataHandler.getInputStream()
public DataHandler
getDataHandler() throws MessagingException
返回用于此部分的内容的 DataHandler。DataHandler 允许客户端操作和获取内容。
return | 内容的 DataHandler |
Throws | MessagingException: |
getDataHandler
DataHandler getDataHandler() throws MessagingException
- Return a DataHandler for the content within this part. The
DataHandler allows clients to operate on as well as retrieve
the content.
- Returns:
- DataHandler for the content
- Throws:
MessagingException
public Object
getContent() throws java.io.IOException, MessagingException
以 Java 对象的形式返回内容。所返回对象的类型当然取决于内容本身。例如,"text/plain" 内容的返回对象通常为 String 对象。"multipart" 内容的返回对象总是 Multipart 子类。对于 DataHandler 系统未知的内容类型,将输入流作为内容返回。
这是一个便捷方法,该方法只调用 DataHandler 的 getContent() 方法。
return | 对象 |
Throws | MessagingException: |
Throws | java.io.IOException: 此异常通常由 DataHandler 抛出。有关更多信息,请参考 javax.activation.DataHandler 的文档。 |
See also | getContent |
getContent
Object getContent() throws IOException, MessagingException
- Return the content as a Java object. The type of the returned
object is of course dependent on the content itself. For example,
the object returned for "text/plain" content is usually a String
object. The object returned for a "multipart" content is always a
Multipart subclass. For content-types that are unknown to the
DataHandler system, an input stream is returned as the content
This is a convenience method that just invokes the DataHandler's getContent() method
- Returns:
- Object
- Throws:
MessagingException
IOException
- this is typically thrown by the DataHandler. Refer to the documentation for javax.activation.DataHandler for more details.- See Also:
DataHandler.getContent()
public void
setDataHandler(DataHandler dh) throws MessagingException
此方法提供设置此部分的内容的机制。DataHandler 包装实际的内容。
dh | 用于内容的 DataHandler。 |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setDataHandler
void setDataHandler(DataHandler dh) throws MessagingException
- This method provides the mechanism to set this part's content.
The DataHandler wraps around the actual content.
- Parameters:
dh
- The DataHandler for the content.- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folder
public void
setContent(Object obj, String type) throws MessagingException
设置此部分的内容的便捷方法。该部分将内容包装在 DataHandler 内部。
注意,为了正常运行,指定类型的 DataContentHandler 类应该可用于 JavaMail 实现,即要执行 setContent(foobar, "application/x-foobar")
,必须安装 "application/x-foobar" 的 DataContentHandler。有关更多信息,请参考 Java Activation Framework。
obj | Java 对象。 |
type | 此对象的 MIME 类型。 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setContent
void setContent(Object obj, String type) throws MessagingException
- A convenience method for setting this part's content. The part
internally wraps the content in a DataHandler.
Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do
setContent(foobar, "application/x-foobar")
, a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information. - Parameters:
obj
- A java object.type
- MIME type of this object.- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folderMessagingException
public void
setText(String text) throws MessagingException
使用 MIME 类型 "text/plain" 将给定的 String 设置为此部分内容的便捷方法。
text | 作为 Message 内容的文本。 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setText
void setText(String text) throws MessagingException
- A convenience method that sets the given String as this
part's content with a MIME type of "text/plain".
- Parameters:
text
- The text that is the Message's content.- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folderMessagingException
public void
setContent(Multipart mp) throws MessagingException
此方法将给定的 Multipart 对象设置为此消息的内容。
mp | 为 Message 的内容的 multipart 对象。 |
Throws | IllegalWriteException: 如果底层实现 不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setContent
void setContent(Multipart mp) throws MessagingException
- This method sets the given Multipart object as this message's
content.
- Parameters:
mp
- The multipart object that is the Message's content- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folderMessagingException
public void
writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
输出此 Part 的字节流。此字节流通常是 Part 属性及其 'content' 中已恰当编码的字节流的聚合。
实现 Part 接口的类决定了要使用的相应编码算法。
字节流通常用于发送。
Throws | java.io.IOException: 如果写入流时发生错误,或者 javax.activation 层发生错误。 |
Throws | MessagingException: 如果获取要写入的数据时发生错误 |
See also | writeTo |
writeTo
void writeTo(OutputStream os) throws IOException, MessagingException
- Output a bytestream for this Part. This bytestream is
typically an aggregration of the Part attributes and
an appropriately encoded bytestream from its 'content'.
Classes that implement the Part interface decide on the appropriate encoding algorithm to be used.
The bytestream is typically used for sending.
- Throws:
IOException
- if an error occurs writing to the stream or if an error is generated by the javax.activation layer.MessagingException
- if an error occurs fetching the data to be written- See Also:
DataHandler.writeTo(java.io.OutputStream)
public String[]
getHeader(String header_name) throws MessagingException
获取具有此头名称的所有头。如果不存在具有此名称的头,则返回 null
。
header_name | 此头的名称 |
return | 具有此名称的所有头的值字段 |
Throws | MessagingException: |
getHeader
String[] getHeader(String header_name) throws MessagingException
- Get all the headers for this header name. Returns
null
if no headers for this header name are available. - Parameters:
header_name
- the name of this header- Returns:
- the value fields for all headers with this name
- Throws:
MessagingException
public void
setHeader(String header_name, String header_value) throws MessagingException
设置此 header_name 的值。使用此新值替换所有现有的头值。
header_name | 此头的名称 |
header_value | 此头的值 |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
setHeader
void setHeader(String header_name, String header_value) throws MessagingException
- Set the value for this header_name. Replaces all existing
header values with this new value.
- Parameters:
header_name
- the name of this headerheader_value
- the value for this header- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folder
public void
addHeader(String header_name, String header_value) throws MessagingException
将此值添加到此 header_name 的现有值中。
header_name | 此头的名称 |
header_value | 此头的值 |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
addHeader
void addHeader(String header_name, String header_value) throws MessagingException
- Add this value to the existing values for this header_name.
- Parameters:
header_name
- the name of this headerheader_value
- the value for this header- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folder
public void
removeHeader(String header_name) throws MessagingException
移除具有此名称的所有头。
header_name | 此头的名称 |
Throws | MessagingException: |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取 |
removeHeader
void removeHeader(String header_name) throws MessagingException
- Remove all headers with this name.
- Parameters:
header_name
- the name of this header- Throws:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this Part is obtained from a READ_ONLY folder
public java.util.Enumeration<E>
getAllHeaders() throws MessagingException
以 Header 对象的枚举形式返回此部分的所有头。
return | Header 对象的枚举 |
Throws | MessagingException: |
getAllHeaders
Enumeration getAllHeaders() throws MessagingException
- Return all the headers from this part as an Enumeration of
Header objects.
- Returns:
- enumeration of Header objects
- Throws:
MessagingException
public java.util.Enumeration<E>
getMatchingHeaders(String[] header_names) throws MessagingException
以 Header 对象的枚举形式返回此部分的匹配头。
return | Header 对象的枚举 |
Throws | MessagingException: |
getMatchingHeaders
Enumeration getMatchingHeaders(String[] header_names) throws MessagingException
- Return matching headers from this part as an Enumeration of
Header objects.
- Returns:
- enumeration of Header objects
- Throws:
MessagingException
public java.util.Enumeration<E>
getNonMatchingHeaders(String[] header_names) throws MessagingException
以 Header 对象的枚举形式返回此封装中不匹配的头。
return | Header 对象的枚举 |
Throws | MessagingException: |
getNonMatchingHeaders
Enumeration getNonMatchingHeaders(String[] header_names) throws MessagingException
- Return non-matching headers from this envelope as an Enumeration
of Header objects.
- Returns:
- enumeration of Header objects
- Throws:
MessagingException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!