javax.mail
Class Multipart

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

public abstract class Multipart
extends java.lang.Object

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.12, 99/12/06
Author:
John Mani

Method Summary
 void addBodyPart(BodyPart part)
          Adds a Part to the multipart.
 void addBodyPart(BodyPart part, int index)
          Adds a BodyPart at position index.
 BodyPart getBodyPart(int index)
          Get the specified Part.
 java.lang.String getContentType()
          Return the content-type of this Multipart.
 int getCount()
          Return the number of enclosed BodyPart objects.
 Part getParent()
          Return the Part that contains this Multipart object, or null if not known.
 boolean removeBodyPart(BodyPart part)
          Remove the specified part from the multipart message.
 void removeBodyPart(int index)
          Remove the part at specified location (starting from 0).
 void setParent(Part parent)
          Set the parent of this Multipart to be the specified Part.
abstract  void writeTo(java.io.OutputStream os)
          Output an appropriately encoded bytestream to the given OutputStream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContentType

public java.lang.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

getCount

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

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

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:
java.lang.IndexOutOfBoundsException - if the given index is out of range.
MessagingException

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

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
java.lang.IndexOutOfBoundsException - if the given index is out of range.
IllegalWriteException - if the underlying implementation does not support modification of existing values

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

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

writeTo

public abstract void writeTo(java.io.OutputStream os)
                      throws java.io.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:
java.io.IOException - if an IO related exception occurs
MessagingException

getParent

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

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