java.lang.Object | +--javax.mail.BodyPart | +--javax.mail.internet.MimeBodyPartAll Implemented Interfaces:
byte[] | Byte array that holds the bytes of the content of this Part. |
InputStream | If the data for this body part was supplied by an InputStream that implements the SharedInputStream interface, contentStream is another such stream representing the content of this body part. |
DataHandler | The DataHandler object representing this Part's content. |
The InternetHeaders object that stores all the headers of this body part. |
An empty MimeBodyPart object is created. |
MimeBodyPart(InputStream is) Constructs a MimeBodyPart by reading and parsing the data from the specified input stream. |
MimeBodyPart(InternetHeaders headers, byte[] content) Constructs a MimeBodyPart using the given header and content bytes. |
void | addHeader(String name, String value) Add this value to the existing values for this name. |
void | addHeaderLine(String line) Add a header line to this body part. |
Enumeration | Get all header lines as an Enumeration of Strings. |
Enumeration | Return all the headers from this Message as an Enumeration of Header objects. |
Object | Return the content as a java object. |
String | Returns the value of the "Content-ID" header field. |
String[] | Get the languages specified in the Content-Language header of this MimePart. |
String | Returns the value of the "Content-MD5" header field. |
InputStream | Produce the raw bytes of the content. |
String | Returns the value of the RFC 822 "Content-Type" header field. |
DataHandler | Return a DataHandler for this body part's content. |
String | Returns the "Content-Description" header field of this body part. |
String | Returns the value of the "Content-Disposition" header field. |
String | Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. |
String | Get the filename associated with this body part. |
String[] | getHeader(String name) Get all the headers for this header_name. |
String | getHeader(String name, String delimiter) Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. |
InputStream | Return a decoded input stream for this body part's "content". |
int | Return the number of lines for the content of this Part. |
Enumeration | getMatchingHeaderLines(String[] names) Get matching header lines as an Enumeration of Strings. |
Enumeration | getMatchingHeaders(String[] names) Return matching headers from this Message as an Enumeration of Header objects. |
Enumeration | getNonMatchingHeaderLines(String[] names) Get non-matching header lines as an Enumeration of Strings. |
Enumeration | getNonMatchingHeaders(String[] names) Return non-matching headers from this Message as an Enumeration of Header objects. |
InputStream | Return an InputStream to the raw data with any Content-Transfer-Encoding intact. |
int | getSize() Return the size of the content of this body part in bytes. |
boolean | isMimeType(String mimeType) Is this Part of the specified MIME type? This method compares only the primaryType and subType. |
void | removeHeader(String name) Remove all headers with this name. |
void | setContent(Object o, String type) A convenience method for setting this body part's content. |
void | setContent(Multipart mp) This method sets the body part's content to a Multipart object. |
void | setContentID(String cid) Set the "Content-ID" header field of this body part. |
void | setContentLanguage(String[] languages) Set the Content-Language header of this MimePart. |
void | setContentMD5(String md5) Set the "Content-MD5" header field of this body part. |
void | setDataHandler(DataHandler dh) This method provides the mechanism to set this body part's content. |
void | setDescription(String description) Set the "Content-Description" header field for this body part. |
void | setDescription(String description, String charset) Set the "Content-Description" header field for this body part. |
void | setDisposition(String disposition) Set the "Content-Disposition" header field of this body part. |
void | setFileName(String filename) Set the filename associated with this body part, if possible. |
void | setHeader(String name, String value) Add this value to the existing values for this name. |
void | setText(String text) Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". |
void | setText(String text, String charset) Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset. |
void | Examine the content of this body part and update the appropriate MIME headers. |
void | writeTo(OutputStream os) Output the body part as an RFC 822 format stream. |
protected byte[] content
protected InputStream contentStream
protected DataHandler dh
protected InternetHeaders headers
public MimeBodyPart()
public MimeBodyPart(InputStream is)
public MimeBodyPart(InternetHeaders headers, byte[] content)
public void addHeader(String name, String value)
public void addHeaderLine(String line)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public Enumeration getAllHeaderLines()
public Enumeration getAllHeaders()
public Object getContent()
getDataHandler().getContent();
- - this is typically thrown by the DataHandler.public String getContentID()
getHeader(name)
to obtain
the requisite header field.
public String[] getContentLanguage()
getHeader(name)
to obtain
the requisite header field.
public String getContentMD5()
getHeader(name)
to obtain
the requisite header field.
protected InputStream getContentStream()
public String getContentType()
getHeader(name)
to obtain
the requisite header field.
public DataHandler getDataHandler()
public String getDescription()
getHeader(name)
to obtain
the requisite header field.
public String getDisposition()
getHeader(name)
to obtain the
requisite header field.
public String getEncoding()
getHeader(name)
to obtain
the requisite header field.
public String getFileName()
public String[] getHeader(String name)
public String getHeader(String name, String delimiter)
public InputStream getInputStream()
- this is typically thrown by the DataHandler.public int getLineCount()
public Enumeration getMatchingHeaderLines(String[] names)
public Enumeration getMatchingHeaders(String[] names)
public Enumeration getNonMatchingHeaderLines(String[] names)
public Enumeration getNonMatchingHeaders(String[] names)
public InputStream getRawInputStream()
getInputStream
method or getContent
method from returning the correct data.
In such a case the application may use this method and attempt to decode
the raw data itself.
This implementation simply calls the getContentStream
method.
public int getSize()
public boolean isMimeType(String mimeType)
mimeType
is the special character '*',
then the subtype is ignored during the comparison.
public void removeHeader(String name)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setContent(Object o, String type)
setContent(foobar, "application/x-foobar")
,
a DataContentHandler for "application/x-foobar" should be installed.
Refer to the Java Activation Framework for more information.
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setContent(Multipart mp)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setContentID(String cid)
cid
parameter is null, any existing "Content-ID" is
removed.
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setContentLanguage(String[] languages)
public void setContentMD5(String md5)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setDataHandler(DataHandler dh)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setDescription(String description)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setDescription(String description, String charset)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setDisposition(String disposition)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setFileName(String filename)
- if the underlying implementation
does not support modification
- if this body part is obtained
from a READ_ONLY folder.public void setHeader(String name, String value)
public void setText(String text)
setText()
version
that takes the charset
parameter.
public void setText(String text, String charset)
protected void updateHeaders()
Message.saveChanges
method.
public void writeTo(OutputStream os)
- if an error occurs writing to the stream or if an
error is generated by the javax.activation layer.
A note on RFC 822 and MIME headers RFC 822 header fields must contain only US-ASCII characters. MIME allows non ASCII characters to be present in certain portions of certain headers, by encoding those characters. RFC 2047 specifies the rules for doing this. The MimeUtility class provided in this package can be used to achieve this. Callers of the
setHeader
,addHeader
, andaddHeaderLine
methods are responsible for enforcing the MIME requirements for the specified headers. In addition, these header fields must be folded (wrapped) before being sent if they exceed the line length limitation for the transport (1000 bytes for SMTP). Received headers may have been folded. The application is responsible for folding and unfolding headers as appropriate.