- java.lang.Object
- 
- jakarta.mail.Multipart
 
- 
- Direct Known Subclasses:
- MimeMultipart
 
 public abstract class Multipart extends java.lang.ObjectMultipart 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 SummaryFields Modifier and Type Field Description protected java.lang.StringcontentTypeThis field specifies the content-type of this multipart object.protected PartparentThePartcontaining thisMultipart, if known.protected java.util.Vector<BodyPart>partsVector of BodyPart objects.protected StreamProviderstreamProviderInstance of stream provider.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedMultipart()Default constructor.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddBodyPart(BodyPart part)Adds a Part to the multipart.voidaddBodyPart(BodyPart part, int index)Adds a BodyPart at positionindex.BodyPartgetBodyPart(int index)Get the specified Part.java.lang.StringgetContentType()Return the content-type of this Multipart.intgetCount()Return the number of enclosed BodyPart objects.PartgetParent()Return thePartthat contains thisMultipartobject, ornullif not known.voidremoveBodyPart(int index)Remove the part at specified location (starting from 0).booleanremoveBodyPart(BodyPart part)Remove the specified part from the multipart message.protected voidsetMultipartDataSource(MultipartDataSource mp)Setup this Multipart object from the given MultipartDataSource.voidsetParent(Part parent)Set the parent of thisMultipartto be the specifiedPart.abstract voidwriteTo(java.io.OutputStream os)Output an appropriately encoded bytestream to the given OutputStream.
 
- 
- 
- 
Field Detail- 
partsprotected java.util.Vector<BodyPart> parts Vector of BodyPart objects.
 - 
contentTypeprotected java.lang.String contentType This field specifies the content-type of this multipart object. It defaults to "multipart/mixed".
 - 
parentprotected Part parent ThePartcontaining thisMultipart, if known.
 - 
streamProviderprotected final StreamProvider streamProvider Instance of stream provider.
 
- 
 - 
Method Detail- 
setMultipartDataSourceprotected 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- for failures
 
 - 
getContentTypepublic java.lang.String getContentType() Return the content-type of this Multipart.This implementation just returns the value of the contentTypefield.- Returns:
- content-type
- See Also:
- contentType
 
 - 
getCountpublic int getCount() throws MessagingExceptionReturn the number of enclosed BodyPart objects.- Returns:
- number of parts
- Throws:
- MessagingException- for failures
- See Also:
- parts
 
 - 
getBodyPartpublic 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- for other failures
 
 - 
removeBodyPartpublic 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
 
 - 
removeBodyPartpublic void removeBodyPart(int index) throws MessagingExceptionRemove 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:
- java.lang.IndexOutOfBoundsException- if the given index is out of range.
- IllegalWriteException- if the underlying implementation does not support modification of existing values
- MessagingException- for other failures
 
 - 
addBodyPartpublic 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:
- IllegalWriteException- if the underlying implementation does not support modification of existing values
- MessagingException- for other failures
 
 - 
addBodyPartpublic void addBodyPart(BodyPart part, int index) throws MessagingException Adds a BodyPart at positionindex. Ifindexis not the last one in the list, the subsequent parts are shifted up. Ifindexis 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:
- IllegalWriteException- if the underlying implementation does not support modification of existing values
- MessagingException- for other failures
 
 - 
writeTopublic abstract void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingExceptionOutput 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- the stream to write to
- Throws:
- java.io.IOException- if an IO related exception occurs
- MessagingException- for other failures
 
 - 
getParentpublic Part getParent() Return thePartthat contains thisMultipartobject, ornullif not known.- Returns:
- the parent Part
 
 - 
setParentpublic void setParent(Part parent) Set the parent of thisMultipartto be the specifiedPart. Normally called by theMessageorBodyPartsetContent(Multipart)method.parentmay benullif theMultipartis being removed from its containingPart.- Parameters:
- parent- the parent Part
 
 
- 
 
-