Class Multipart
- Direct Known Subclasses:
MimeMultipart
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 TypeFieldDescriptionprotected String
This field specifies the content-type of this multipart object.protected Part
ThePart
containing thisMultipart
, if known.Vector of BodyPart objects.protected final StreamProvider
Instance of stream provider. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBodyPart
(BodyPart part) Adds a Part to the multipart.void
addBodyPart
(BodyPart part, int index) Adds a BodyPart at positionindex
.getBodyPart
(int index) Get the specified Part.Return the content-type of this Multipart.int
getCount()
Return the number of enclosed BodyPart objects.Return thePart
that contains thisMultipart
object, ornull
if not known.void
removeBodyPart
(int index) Remove the part at specified location (starting from 0).boolean
removeBodyPart
(BodyPart part) Remove the specified part from the multipart message.protected void
Setup this Multipart object from the given MultipartDataSource.void
Set the parent of thisMultipart
to be the specifiedPart
.abstract void
writeTo
(OutputStream os) Output an appropriately encoded bytestream to the given OutputStream.
-
Field Details
-
parts
Vector of BodyPart objects. -
contentType
This field specifies the content-type of this multipart object. It defaults to "multipart/mixed". -
parent
ThePart
containing thisMultipart
, if known.- Since:
- JavaMail 1.1
-
streamProvider
Instance of stream provider.- Since:
- JavaMail 2.1
-
-
Constructor Details
-
Multipart
protected Multipart()Default constructor. An empty Multipart object is created.
-
-
Method Details
-
setMultipartDataSource
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
-
getContentType
Return the content-type of this Multipart.This implementation just returns the value of the
contentType
field.- Returns:
- content-type
- See Also:
-
getCount
Return the number of enclosed BodyPart objects.- Returns:
- number of parts
- Throws:
MessagingException
- for failures- See Also:
-
getBodyPart
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
- for other failures
-
removeBodyPart
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 existsIllegalWriteException
- if the underlying implementation does not support modification of existing values
-
removeBodyPart
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:
IndexOutOfBoundsException
- if the given index is out of range.IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
addBodyPart
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 valuesMessagingException
- for other failures
-
addBodyPart
Adds a BodyPart at positionindex
. Ifindex
is not the last one in the list, the subsequent parts are shifted up. Ifindex
is larger than the number of parts present, the BodyPart is appended to the end.- Parameters:
part
- The BodyPart to be insertedindex
- Location where to insert the part- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
writeTo
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
- the stream to write to- Throws:
IOException
- if an IO related exception occursMessagingException
- for other failures
-
getParent
Return thePart
that contains thisMultipart
object, ornull
if not known.- Returns:
- the parent Part
- Since:
- JavaMail 1.1
-
setParent
Set the parent of thisMultipart
to be the specifiedPart
. Normally called by theMessage
orBodyPart
setContent(Multipart)
method.parent
may benull
if theMultipart
is being removed from its containingPart
.- Parameters:
parent
- the parent Part- Since:
- JavaMail 1.1
-