public interface Part
The content of a part is available in various forms:
getDataHandler
method.
getInputStream
method.
getContent
method.
writeTo
method can be used to write the part to a
byte stream in mail-safe form suitable for transmission.
In MIME terms, Part models an Entity (RFC 2045, Section 2.4).
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTACHMENT
This part should be presented as an attachment.
|
static java.lang.String |
INLINE
This part should be presented inline.
|
Modifier and Type | Method and Description |
---|---|
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds the specified value to the existing values for this header name.
|
java.util.Enumeration |
getAllHeaders()
Returns all the headers from this part.
|
java.lang.Object |
getContent()
Returns the content of this part as a Java object.
|
java.lang.String |
getContentType()
Returns the content-type of the content of this part, or
null if the content-type could not be determined. |
javax.activation.DataHandler |
getDataHandler()
Returns a data handler for the content of this part.
|
java.lang.String |
getDescription()
Returns the description of this part.
|
java.lang.String |
getDisposition()
Returns the disposition of this part.
|
java.lang.String |
getFileName()
Returns the filename associated with this part, if available.
|
java.lang.String[] |
getHeader(java.lang.String name)
Returns all the values for the specified header name, or
null if no such headers are available. |
java.io.InputStream |
getInputStream()
Returns an input stream for reading the content of this part.
|
int |
getLineCount()
Returns the number of lines in the content of this part, or -1 if the
number cannot be determined.
|
java.util.Enumeration |
getMatchingHeaders(java.lang.String[] names)
Returns the matching headers from this part.
|
java.util.Enumeration |
getNonMatchingHeaders(java.lang.String[] names)
Returns the non-matching headers from this part.
|
int |
getSize()
Returns the size of the content of this part in bytes, or -1 if the
size cannot be determined.
|
boolean |
isMimeType(java.lang.String mimeType)
Is this part of the specified MIME type?
This method compares only the primary type and subtype.
|
void |
removeHeader(java.lang.String name)
Removes all headers of the specified name.
|
void |
setContent(Multipart mp)
Sets the multipart content of this part.
|
void |
setContent(java.lang.Object obj,
java.lang.String type)
Sets the content of this part using the specified object.
|
void |
setDataHandler(javax.activation.DataHandler dh)
Sets the content of this part using the specified data handler.
|
void |
setDescription(java.lang.String description)
Sets the description of this part.
|
void |
setDisposition(java.lang.String disposition)
Sets the disposition of this part.
|
void |
setFileName(java.lang.String filename)
Sets the filename associated with this part.
|
void |
setHeader(java.lang.String name,
java.lang.String value)
Sets the value for the specified header name.
|
void |
setText(java.lang.String text)
Sets the textual content of this part, using a MIME type of
text/plain . |
void |
writeTo(java.io.OutputStream os)
Writes this part to the specified byte stream.
|
static final java.lang.String ATTACHMENT
static final java.lang.String INLINE
int getSize() throws MessagingException
Note that the size may not be an exact measure of the content size, but will be suitable for display in a user interface to give the user an idea of the size of this part.
MessagingException
int getLineCount() throws MessagingException
MessagingException
java.lang.String getContentType() throws MessagingException
null
if the content-type could not be determined.
The MIME typing system is used to name content-types.
MessagingException
boolean isMimeType(java.lang.String mimeType) throws MessagingException
If the subtype of mimeType
is the special character '*',
then the subtype is ignored during the comparison.
MessagingException
java.lang.String getDisposition() throws MessagingException
MessagingException
void setDisposition(java.lang.String disposition) throws MessagingException
disposition
- the disposition of this partIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
java.lang.String getDescription() throws MessagingException
MessagingException
void setDescription(java.lang.String description) throws MessagingException
description
- the description of this partIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this Part is obtained from
a READ_ONLY folderMessagingException
java.lang.String getFileName() throws MessagingException
MessagingException
void setFileName(java.lang.String filename) throws MessagingException
filename
- the filename to associate with this partIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this Part is obtained from
a READ_ONLY folderMessagingException
java.io.InputStream getInputStream() throws java.io.IOException, MessagingException
java.io.IOException
- when a data handler error occursMessagingException
javax.activation.DataHandler getDataHandler() throws MessagingException
MessagingException
java.lang.Object getContent() throws java.io.IOException, MessagingException
java.io.IOException
- when a data handler error occursMessagingException
void setDataHandler(javax.activation.DataHandler dh) throws MessagingException
dh
- the data handler for the contentIllegalWriteException
- if the underlying implementation
does not support modificationjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void setContent(java.lang.Object obj, java.lang.String type) throws MessagingException
obj
- a Java objecttype
- the MIME content-type of this objectIllegalWriteException
- if the underlying implementation
does not support modificationjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void setText(java.lang.String text) throws MessagingException
text/plain
.text
- the textual contentIllegalWriteException
- if the underlying implementation
does not support modificationjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void setContent(Multipart mp) throws MessagingException
mp
- the multipart contentIllegalWriteException
- if the underlying implementation
does not support modificationjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
java.io.IOException
- if an error occurs writing to the stream
or if an error occurs in the data handler system.MessagingException
- if an error occurs fetching the data
to be writtenjava.lang.String[] getHeader(java.lang.String name) throws MessagingException
null
if no such headers are available.name
- the header nameMessagingException
void setHeader(java.lang.String name, java.lang.String value) throws MessagingException
name
- the header namevalue
- the new valueIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void addHeader(java.lang.String name, java.lang.String value) throws MessagingException
name
- the header namevalue
- the value to addIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
void removeHeader(java.lang.String name) throws MessagingException
name
- the header nameIllegalWriteException
- if the underlying implementation
does not support modification of this headerjava.lang.IllegalStateException
- if this part is obtained from
a READ_ONLY folderMessagingException
java.util.Enumeration getAllHeaders() throws MessagingException
MessagingException
java.util.Enumeration getMatchingHeaders(java.lang.String[] names) throws MessagingException
names
- the header names to matchMessagingException
java.util.Enumeration getNonMatchingHeaders(java.lang.String[] names) throws MessagingException
names
- the header names to ignoreMessagingException