Top Description Fields Constructors Methods
javax.mail

public abstract Class Multipart

extends Object
Class Inheritance
Known Direct Subclasses
javax.mail.internet.MimeMultipart
Imports
java.util.Vector, java.io.InputStream, .OutputStream, .IOException, javax.activation.DataSource

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.

Author
John Mani

Field Summary

Modifier and TypeField and Description
protected String
contentType

This field specifies the content-type of this multipart object.

protected Part
parent

The Part containing this Multipart, if known.

protected Vector<BodyPart>
parts

Vector of BodyPart objects.

Constructor Summary

AccessConstructor and Description
protected
Multipart()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addBodyPart(BodyPart
The Part to be appended
part
)

Adds a Part to the multipart.

public synchronized void
addBodyPart(BodyPart
The BodyPart to be inserted
part
,
int
Location where to insert the part
index
)

Adds a BodyPart at position index.

public synchronized BodyPart

Returns:

the Part
getBodyPart
(int
the index of the desired Part
index
)

Get the specified Part.

public synchronized String

Returns:

content-type
getContentType
()

Return the content-type of this Multipart.

public synchronized int

Returns:

number of parts
getCount
()

Return the number of enclosed BodyPart objects.

public synchronized Part

Returns:

the parent Part
getParent
()

Return the Part that contains this Multipart object, or null if not known.

public synchronized boolean

Returns:

true if part removed, false otherwise
removeBodyPart
(BodyPart
The part to remove
part
)

Remove the specified part from the multipart message.

public synchronized void
removeBodyPart(int
Index of the part to remove
index
)

Remove the part at specified location (starting from 0).

protected synchronized void
setMultipartDataSource(MultipartDataSource
Multipart datasource
mp
)

Setup this Multipart object from the given MultipartDataSource.

public synchronized void
setParent(Part
the parent Part
parent
)

Set the parent of this Multipart to be the specified Part.

public abstract void
writeTo(OutputStream
the stream to write to
os
)

Output an appropriately encoded bytestream to the given OutputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentTypeback to summary
protected String contentType

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

parentback to summary
protected Part parent

The Part containing this Multipart, if known.

Since
JavaMail 1.1
partsback to summary
protected Vector<BodyPart> parts

Vector of BodyPart objects.

Constructor Detail

Multipartback to summary
protected Multipart()

Default constructor. An empty Multipart object is created.

Method Detail

addBodyPartback to summary
public synchronized void addBodyPart(BodyPart part) throws MessagingException

Adds a Part to the multipart. The BodyPart is appended to the list of existing Parts.

Parameters
part:BodyPart

The Part to be appended

Exceptions
MessagingException:
for other failures
IllegalWriteException:
if the underlying implementation does not support modification of existing values
addBodyPartback to summary
public synchronized 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:BodyPart

The BodyPart to be inserted

index:int

Location where to insert the part

Exceptions
MessagingException:
for other failures
IllegalWriteException:
if the underlying implementation does not support modification of existing values
getBodyPartback to summary
public synchronized BodyPart getBodyPart(int index) throws MessagingException

Get the specified Part. Parts are numbered starting at 0.

Parameters
index:int

the index of the desired Part

Returns:BodyPart

the Part

Exceptions
MessagingException:
for other failures
IndexOutOfBoundsException:
if the given index is out of range.
getContentTypeback to summary
public synchronized String getContentType()

Return the content-type of this Multipart.

This implementation just returns the value of the contentType field.

Returns:String

content-type

See Also
contentType
getCountback to summary
public synchronized int getCount() throws MessagingException

Return the number of enclosed BodyPart objects.

Returns:int

number of parts

Exceptions
MessagingException:
for failures
See Also
parts
getParentback to summary
public synchronized Part getParent()

Return the Part that contains this Multipart object, or null if not known.

Returns:Part

the parent Part

Since
JavaMail 1.1
removeBodyPartback to summary
public synchronized 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:BodyPart

The part to remove

Returns:boolean

true if part removed, false otherwise

Exceptions
MessagingException:
if no such Part exists
IllegalWriteException:
if the underlying implementation does not support modification of existing values
removeBodyPartback to summary
public synchronized 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:int

Index of the part to remove

Exceptions
MessagingException:
for other failures
IndexOutOfBoundsException:
if the given index is out of range.
IllegalWriteException:
if the underlying implementation does not support modification of existing values
setMultipartDataSourceback to summary
protected synchronized 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:MultipartDataSource

Multipart datasource

Exceptions
MessagingException:
for failures
setParentback to summary
public synchronized 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.

Parameters
parent:Part

the parent Part

Since
JavaMail 1.1
writeToback to summary
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.

Parameters
os:OutputStream

the stream to write to

Exceptions
IOException:
if an IO related exception occurs
MessagingException:
for other failures