- java.lang.Object
-
- javax.mail.Multipart
-
- Direct Known Subclasses:
- MimeMultipart
public abstract class Multipart extends 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.
- Author:
- John Mani
-
-
Field Summary
Fields Modifier and Type Field and Description protected String
contentType
This field specifies the content-type of this multipart object.protected Part
parent
ThePart
containing thisMultipart
, if known.protected Vector
parts
Vector of BodyPart objects.
-
Constructor Summary
Constructors Modifier Constructor and Description protected
Multipart()
Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description void
addBodyPart(BodyPart part)
Adds a Part to the multipart.void
addBodyPart(BodyPart part, int index)
Adds a BodyPart at positionindex
.BodyPart
getBodyPart(int index)
Get the specified Part.String
getContentType()
Return the content-type of this Multipart.int
getCount()
Return the number of enclosed BodyPart objects.Part
getParent()
Return thePart
that contains thisMultipart
object, ornull
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).protected void
setMultipartDataSource(MultipartDataSource mp)
Setup this Multipart object from the given MultipartDataSource.void
setParent(Part parent)
Set the parent of thisMultipart
to be the specifiedPart
.abstract void
writeTo(OutputStream os)
Output an appropriately encoded bytestream to the given OutputStream.
-
-
-
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
ThePart
containing thisMultipart
, if known.- Since:
- JavaMail 1.1
-
-
Constructor Detail
-
Multipart
protected Multipart()
Default constructor. An empty Multipart object is created.
-
-
Method Detail
-
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
-
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
-
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:
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 existsIllegalWriteException
- 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
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 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:
MessagingException
IllegalWriteException
- if the underlying implementation does not support modification of existing values
-
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 occursMessagingException
-
getParent
public Part getParent()
Return thePart
that contains thisMultipart
object, ornull
if not known.- Since:
- JavaMail 1.1
-
setParent
public void setParent(Part parent)
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
.- Since:
- JavaMail 1.1
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/mail/multipart.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.