public class MultiPartOutput extends java.lang.Object implements MimeConstants
When a getBytes() is performed, then the output is something similar to
Message-ID: db03b6ef-ffff-ffc0-019b-04e2b47a4d8e
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1_33189144.1047351507632"
Content-Length: 383
------=_Part_1_33189144.1047351507632
Content-Id: AdaptrisMessage/payload
This is the message 03/11/2003 01:57 PM
------=_Part_1_33189144.1047351507632
Content-Id: AdaptrisMessage/metadata
workflowId=loopback
previousGuid=db03b6ef-ffff-ffc0-019b-04e2b47a4d8e
emailmessageid=<200303110257.h2B2v9sC030299@localhost.localdomain>
------=_Part_1_33189144.1047351507632--
With each additional call to addPart()>/code> an additional mime
bodypart is created. Repeated calls to
getBytes()
will return the latest version of the MimeMultiPart as written
out. There is no guarantee that this is the same as the last call to getBytes()
as the part id's may change.
If non-unique content-id's are used for each bodypart, then an invocation of removePart(String)
will remove
all matching body parts.
CONTENT_TYPE_OCTET_STREAM, CONTENT_TYPE_TEXT_PLAIN, CONTENT_TYPE_WWW_FORM_URLENCODE, ENCODING_7BIT, ENCODING_8BIT, ENCODING_BASE64, ENCODING_BINARY, ENCODING_QUOTED, ENCODING_UUENCODE, HEADER_CONTENT_DESC, HEADER_CONTENT_ENCODING, HEADER_CONTENT_ID, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_MESSAGE_ID, HEADER_MIME_VERSION
Constructor and Description |
---|
MultiPartOutput(java.lang.String mimeId)
Constructor.
|
MultiPartOutput(java.lang.String mimeId,
java.lang.String subtype)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addPart(byte[] payload,
java.lang.String contentId)
Add a new part to the mime multipart.
|
void |
addPart(byte[] payload,
java.lang.String encoding,
java.lang.String contentId)
Add a new part to the mime multipart.
|
void |
addPart(javax.mail.internet.MimeBodyPart part,
java.lang.String contentId)
Add a new part to the mime multipart.
|
void |
addPart(java.lang.String payload,
java.lang.String contentId)
Add a new part to the mime multipart.
|
void |
addPart(java.lang.String payload,
java.lang.String encoding,
java.lang.String contentId)
Add a new part to the mime multipart.
|
byte[] |
getBytes()
Get bytes created by this multi-part.
|
javax.mail.internet.InternetHeaders |
getMimeHeader()
Return the underlying mime header that will be used to write the headers.
|
void |
removePart(java.lang.String contentId)
Remove a part from this multipart output.
|
void |
setHeader(java.lang.String key,
java.lang.String value)
Set an arbitary header to the headers prefixed to the start of the multipart.
|
void |
writeTo(java.io.OutputStream out)
Write the multipart to the given output stream.
|
void |
writeTo(java.io.OutputStream out,
java.io.File tempFile)
Write the multipart to the given outputstream.
|
public MultiPartOutput(java.lang.String mimeId) throws javax.mail.MessagingException
This implicitly sets the multipart sub-type to be mixed.
mimeId
- the Message-ID header to assign to this multi-partjavax.mail.MessagingException
- if the bytes did not contain a valid MimeMultiPartpublic MultiPartOutput(java.lang.String mimeId, java.lang.String subtype) throws javax.mail.MessagingException
mimeId
- the Message-ID header to assign to this multi-partsubtype
- the multi-part subtype.javax.mail.MessagingException
- if there was a failure to create the underlying Mime Multipartpublic void addPart(java.lang.String payload, java.lang.String encoding, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
payload
- the data.encoding
- the encoding to applycontentId
- the id to set the content with.javax.mail.MessagingException
- if there was a failure adding the part. MimeMultiPartjava.io.IOException
- if there was an IOExceptionpublic void addPart(java.lang.String payload, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
payload
- the data.contentId
- the id to set the content with.javax.mail.MessagingException
- if there was a failure adding the part. MimeMultiPartjava.io.IOException
- if there was an IOExceptionpublic void addPart(byte[] payload, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
payload
- the data.contentId
- the id to set the content with.javax.mail.MessagingException
- if there was a failure adding the part. MimeMultiPartjava.io.IOException
- if there was an IOExceptionpublic void addPart(byte[] payload, java.lang.String encoding, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
payload
- the data.encoding
- the encoding to applycontentId
- the id to set the content with.javax.mail.MessagingException
- on error manipulating the bodypartjava.io.IOException
- on general IO error.public void addPart(javax.mail.internet.MimeBodyPart part, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
part
- an already existing mimebody partcontentId
- the id to set the content with.javax.mail.MessagingException
- on error manipulating the bodypartjava.io.IOException
- on general IO error.public void removePart(java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
If non-unique content-id's are used for each bodypart, then an invocation of removePart(String)
will remove
all matching body parts.
contentId
- the content-id associated with a previously added part.javax.mail.MessagingException
- if there was a failure removing the part.java.io.IOException
- if there was an IOExceptionpublic byte[] getBytes() throws javax.mail.MessagingException, java.io.IOException
javax.mail.MessagingException
- if there was a failure retrieving the bytes.java.io.IOException
- if there was an IOExceptionpublic void writeTo(java.io.OutputStream out) throws javax.mail.MessagingException, java.io.IOException
out
- the output stream.javax.mail.MessagingException
- if there was a failure retrieving the bytes.java.io.IOException
- if there was an IOExceptionpublic void writeTo(java.io.OutputStream out, java.io.File tempFile) throws javax.mail.MessagingException, java.io.IOException
out
- the output stream.tempFile
- if not null, then use the specified file to stream the parts to first.javax.mail.MessagingException
java.io.IOException
public void setHeader(java.lang.String key, java.lang.String value)
The Content-Type and Content-Length will always be overridden with the content-type and length of the mime multipart
key
- the keyvalue
- the value.InternetHeaders
public javax.mail.internet.InternetHeaders getMimeHeader()