FileDocCategorySizeDatePackage
Multipart.javaAPI DocAndroid 1.5 API6387Wed May 06 22:42:46 BST 2009org.apache.james.mime4j.message

Multipart

public class Multipart extends Object implements Body
Represents a MIME multipart body (see RFC 2045).A multipart body has a ordered list of body parts. The multipart body also has a preamble and epilogue. The preamble consists of whatever characters appear before the first body part while the epilogue consists of whatever characters come after the last body part.
version
$Id: Multipart.java,v 1.3 2004/10/02 12:41:11 ntherning Exp $

Fields Summary
private String
preamble
private String
epilogue
private List
bodyParts
private Entity
parent
private String
subType
Constructors Summary
public Multipart()
Creates a new empty Multipart instance.


               
      
    
Methods Summary
public voidaddBodyPart(BodyPart bodyPart)
Adds a body part to the end of the list of body parts.

param
bodyPart the body part.

        bodyParts.add(bodyPart);
        bodyPart.setParent(parent);
    
public java.util.ListgetBodyParts()
Gets the list of body parts. The list is immutable.

return
the list of BodyPart objects.

        return Collections.unmodifiableList(bodyParts);
    
private java.lang.StringgetBoundary()
Return the boundory of the parent Entity

return
boundery

        Entity e = getParent();
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                Field.CONTENT_TYPE);
        return cField.getBoundary();
    
private java.lang.StringgetCharset()

        Entity e = getParent();
        String charString = ((ContentTypeField) e.getHeader().getField(Field.CONTENT_TYPE)).getCharset();
        return charString;
    
public java.lang.StringgetEpilogue()
Gets the epilogue.

return
the epilogue.

        return epilogue;
    
public EntitygetParent()

see
org.apache.james.mime4j.message.Body#getParent()

        return parent;
    
public java.lang.StringgetPreamble()
Gets the preamble.

return
the preamble.

        return preamble;
    
public java.lang.StringgetSubType()
Gets the multipart sub-type. E.g. alternative (the default) or parallel. See RFC 2045 for common sub-types and their meaning.

return
the multipart sub-type.

        return subType;
    
public voidsetBodyParts(java.util.List bodyParts)
Sets the list of body parts.

param
bodyParts the new list of BodyPart objects.

        this.bodyParts = bodyParts;
        for (Iterator it = bodyParts.iterator(); it.hasNext();) {
            ((BodyPart) it.next()).setParent(parent);
        }
    
public voidsetEpilogue(java.lang.String epilogue)
Sets the epilogue.

param
epilogue the epilogue.

        this.epilogue = epilogue;
    
public voidsetParent(Entity parent)

see
org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity)

        this.parent = parent;
        for (Iterator it = bodyParts.iterator(); it.hasNext();) {
            ((BodyPart) it.next()).setParent(parent);
        }
    
public voidsetPreamble(java.lang.String preamble)
Sets the preamble.

param
preamble the preamble.

        this.preamble = preamble;
    
public voidsetSubType(java.lang.String subType)
Sets the multipart sub-type. E.g. alternative or parallel. See RFC 2045 for common sub-types and their meaning.

param
subType the sub-type.

        this.subType = subType;
    
public voidwriteTo(java.io.OutputStream out)

see
org.apache.james.mime4j.message.Body#writeTo(java.io.OutputStream)

        String boundary = getBoundary();
        List bodyParts = getBodyParts();

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, CharsetUtil.getCharset(getCharset())),8192);
        
        writer.write(getPreamble() + "\r\n");

        for (int i = 0; i < bodyParts.size(); i++) {
            writer.write(boundary + "\r\n");
            ((BodyPart) bodyParts.get(i)).writeTo(out);
        }

        writer.write(getEpilogue() + "\r\n");
        writer.write(boundary + "--" + "\r\n");