Multipart (Java EE 5)

Java EE API


javax.mail Class Multipart

java.lang.Object
  extended by javax.mail.Multipart
Direct Known Subclasses:
MimeMultipart

public abstract class Multipart
extends Object

Extended by: MimeMultipart

Multipart 是保存多个正文部分的容器。Multipart 提供获取和设置其子部分的方法。

Multipart 还充当多数 Multipart DataContentHandler 所返回的内容对象的基类。例如,对其源为 "multipart/signed" 数据源的 DataHandler 调用 getContent() 方法可能返回相应的 Multipart 子类。

一些消息传递系统提供不同的 Multipart 子类型。例如,MIME 指定了一组包括 "alternative"、"mixed"、"related"、"parallel"、"signed" 等在内的子类型。

Multipart 是一个抽象类。子类提供实际实现。

英文文档:

Multipart is a container that holds multiple body parts. Multipart provides methods to retrieve and set its subparts.

Multipart also acts as the base class for the content object returned by most Multipart DataContentHandlers. For example, invoking getContent() on a DataHandler whose source is a "multipart/signed" data source may return an appropriate subclass of Multipart.

Some messaging systems provide different subtypes of Multiparts. For example, MIME specifies a set of subtypes that include "alternative", "mixed", "related", "parallel", "signed", etc.

Multipart is an abstract class. Subclasses provide actual implementations.

Version:
1.16, 07/05/04
Author:
John Mani

Field Summary
protected  String
protected  Part
protected  Vector
 
Constructor Summary
protected
 
Method Summary
 void
 void
 BodyPart
 String
 int
 Part
 boolean
 void
protected  void
 void
abstract  void
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

parts

protected Vector parts
Vector of BodyPart objects.


英文文档:

contentType

protected String contentType
This field specifies the content-type of this multipart object. It defaults to "multipart/mixed".


英文文档:

parent

protected Part parent
The Part containing this Multipart, if known.

Since:
JavaMail 1.1

Constructor Detail

protected Multipart()
默认构造方法。创建一个空的 Multipart 对象。
英文文档:

Multipart

protected Multipart()
Default constructor. An empty Multipart object is created.

Method Detail

protected void setMultipartDataSource(MultipartDataSource mp) throws MessagingException
根据给定 MultipartDataSource 设置此 Multipart 对象。

该方法将 MultipartDataSource 的 BodyPart 对象添加到此 Multipart 中。此 Multipart 的 contentType 被设置为 MultipartDataSource 的内容类型。

此方法通常在以下情况下使用:拥有已经预先解析成单独正文部分的 Multipart 数据源(例如 IMAP 数据源),但需要创建表示特定 multipart 子类型的相应 Multipart 子类。

mp Multipart 数据源

英文文档:

setMultipartDataSource

protected void setMultipartDataSource(MultipartDataSource mp)
                               throws MessagingException
Setup this Multipart object from the given MultipartDataSource.

The method adds the MultipartDataSource's BodyPart objects into this Multipart. This Multipart's contentType is set to that of the MultipartDataSource.

This method is typically used in those cases where one has a multipart data source that has already been pre-parsed into the individual body parts (for example, an IMAP datasource), but needs to create an appropriate Multipart subclass that represents a specific multipart subtype.

Parameters:
mp - Multipart datasource
Throws:
MessagingException

public String getContentType()
返回此 Multipart 的内容类型。

此实现只返回 contentType 字段的值。

return 内容类型
See also contentType

英文文档:

getContentType

public String getContentType()
Return the content-type of this Multipart.

This implementation just returns the value of the contentType field.

Returns:
content-type
See Also:
contentType

public int getCount() throws MessagingException
返回封闭的 BodyPart 对象的数量。

return 部分数
See also parts

英文文档:

getCount

public int getCount()
             throws MessagingException
Return the number of enclosed BodyPart objects.

Returns:
number of parts
Throws:
MessagingException
See Also:
parts

public BodyPart getBodyPart(int index) throws MessagingException
获取指定的 Part。Part 是从 0 开始编号的。
index 所需 Part 的索引
return Part
ThrowsIndexOutOfBoundsException: 如果给定索引超出范围。
ThrowsMessagingException:
英文文档:

getBodyPart

public BodyPart getBodyPart(int index)
                     throws MessagingException
Get the specified Part. Parts are numbered starting at 0.

Parameters:
index - the index of the desired Part
Returns:
the Part
Throws:
IndexOutOfBoundsException - if the given index is out of range.
MessagingException

public boolean removeBodyPart(BodyPart part) throws MessagingException
从 multipart 消息中移除指定的部分。将所有部分向移除部分移动一位。
part 要移除的部分
return 如果移除了 part,则返回 true;否则返回 false
ThrowsMessagingException: 如果不存在此类 Part
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
英文文档:

removeBodyPart

public boolean removeBodyPart(BodyPart part)
                       throws MessagingException
Remove the specified part from the multipart message. Shifts all the parts after the removed part down one.

Parameters:
part - The part to remove
Returns:
true if part removed, false otherwise
Throws:
MessagingException - if no such Part exists
IllegalWriteException - if the underlying implementation does not support modification of existing values

public void removeBodyPart(int index) throws MessagingException
移除指定位置(从 0 开始)的部分。将所有部分向移除部分移动一位。
index 要移除部分的索引
ThrowsMessagingException:
ThrowsIndexOutOfBoundsException: 如果给定索引超出范围。
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
英文文档:

removeBodyPart

public void removeBodyPart(int index)
                    throws MessagingException
Remove the part at specified location (starting from 0). Shifts all the parts after the removed part down one.

Parameters:
index - Index of the part to remove
Throws:
MessagingException
IndexOutOfBoundsException - if the given index is out of range.
IllegalWriteException - if the underlying implementation does not support modification of existing values

public void addBodyPart(BodyPart part) throws MessagingException
将 Part 添加到 multipart。BodyPart 将被添加到现有的 Part 列表。
part 要添加的 Part
ThrowsMessagingException:
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
英文文档:

addBodyPart

public void addBodyPart(BodyPart part)
                 throws MessagingException
Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.

Parameters:
part - The Part to be appended
Throws:
MessagingException
IllegalWriteException - if the underlying implementation does not support modification of existing values

public void addBodyPart(BodyPart part, int index) throws MessagingException
index 处添加 BodyPart。如果 index 不是列表中的最后一个,则后续部分将向上移。如果 index 大于现有的部分数,则将在末尾添加 BodyPart。
part 要插入的 BodyPart
index 插入部分的位置
ThrowsMessagingException:
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
英文文档:

addBodyPart

public void addBodyPart(BodyPart part,
                        int index)
                 throws MessagingException
Adds a BodyPart at position index. If index is not the last one in the list, the subsequent parts are shifted up. If index is larger than the number of parts present, the BodyPart is appended to the end.

Parameters:
part - The BodyPart to be inserted
index - Location where to insert the part
Throws:
MessagingException
IllegalWriteException - if the underlying implementation does not support modification of existing values

abstract public void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
将相应的已编码字节流输出到给定的 OutputStream。实现子类决定相应的编码算法。字节流通常用于发送。
Throwsjava.io.IOException: 如果发生与 IO 相关的异常
ThrowsMessagingException:
英文文档:

writeTo

public abstract void writeTo(OutputStream os)
                      throws IOException,
                             MessagingException
Output an appropriately encoded bytestream to the given OutputStream. The implementation subclass decides the appropriate encoding algorithm to be used. The bytestream is typically used for sending.

Throws:
IOException - if an IO related exception occurs
MessagingException

public Part getParent()
返回包含此 Multipart 对象的 Part;如果未知,则返回 null
since
JavaMail 1.1
英文文档:

getParent

public Part getParent()
Return the Part that contains this Multipart object, or null if not known.

Since:
JavaMail 1.1

public void setParent(Part parent)
将此 Multipart 的父 Multipart 设置为指定的 Part。通常由 MessageBodyPart setContent(Multipart) 方法调用。如果要从包含 Part 中移除 Multipart,则 parent 可能为 null
since
JavaMail 1.1
英文文档:

setParent

public void setParent(Part parent)
Set the parent of this Multipart to be the specified Part. Normally called by the Message or BodyPart setContent(Multipart) method. parent may be null if the Multipart is being removed from its containing Part.

Since:
JavaMail 1.1


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!