javax.mail.internet
public class MimeBodyPart extends BodyPart implements MimePart
The string representation of RFC822 and MIME header fields must contain
only US-ASCII characters. Non US-ASCII characters must be encoded as per
the rules in RFC 2047. This class does not enforce those rules; the
caller is expected to use MimeUtility
to ensure that header
values are correctly encoded.
Version: 1.4
Field Summary | |
---|---|
protected byte[] | content
The bytes of the content of this part, if the part can be stored in
memory. |
protected InputStream | contentStream
A SharedInputStream containing the bytes of this part, if it cannot be
stored in memory. |
protected DataHandler | dh
The data handler managing this part's content. |
protected InternetHeaders | headers
The headers of this body part. |
Constructor Summary | |
---|---|
MimeBodyPart()
Constructor for an empty MIME body part. | |
MimeBodyPart(InputStream is)
Constructor with an input stream.
| |
MimeBodyPart(InternetHeaders headers, byte[] content)
Constructor with headers and byte content. |
Method Summary | |
---|---|
void | addHeader(String name, String value)
Adds the specified header. |
void | addHeaderLine(String line)
Adds an RFC 822 header-line to this part. |
void | attachFile(File file)
Use the specified file as the content for this part. |
void | attachFile(String file)
Use the specified file as the content for this part. |
Enumeration | getAllHeaderLines()
Returns all the header-lines. |
Enumeration | getAllHeaders()
Returns all the headers. |
Object | getContent()
Returns this part's content as a Java object. |
String | getContentID()
Returns the value of the Content-ID header field. |
String[] | getContentLanguage()
Returns the languages specified in the Content-Language header of this
part, as defined by RFC 1766. |
String | getContentMD5()
Returns the value of the Content-MD5 header field. |
protected InputStream | getContentStream()
Returns the unencoded bytes of the content. |
String | getContentType()
Returns the value of the RFC 822 Content-Type header field, or
"text/plain" if the header is not available. |
DataHandler | getDataHandler()
Returns a data handler for accessing this part's content. |
String | getDescription()
Returns the Content-Description header field of this part.
|
String | getDisposition()
Returns the value of the RFC 822 Content-Disposition header field, or
null if the header is not available. |
String | getEncoding()
Returns the value of the Content-Transfer-Encoding header field. |
String | getFileName()
Returns the filename associated with this body part.
|
String[] | getHeader(String name)
Returns all the values for the specified header name.
|
String | getHeader(String name, String delimiter)
Returns all the values for the specified header name as a single
string, with headers separated by the given delimiter.
|
InputStream | getInputStream()
Returns a decoded input stream for this part's content. |
int | getLineCount()
Returns the number of lines in the content of this body part, or -1 if
this number cannot be determined.
|
Enumeration | getMatchingHeaderLines(String[] names)
Returns all the header-lines with any of the given names. |
Enumeration | getMatchingHeaders(String[] names)
Returns all the headers with any of the given names. |
Enumeration | getNonMatchingHeaderLines(String[] names)
Returns all the header-lines without any of the given names. |
Enumeration | getNonMatchingHeaders(String[] names)
Returns all the headers without any of the given names. |
InputStream | getRawInputStream()
Returns the unencoded bytes of the content without applying any
content transfer decoding. |
int | getSize()
Returns the size of the content of this body part in bytes, or -1 if
the size cannot be determined.
|
boolean | isMimeType(String mimeType)
Indicates whether this part is of the specified MIME type.
|
void | removeHeader(String name)
Removes all headers with the specified name. |
void | saveFile(File file)
Saves the content of this part to the specified file. |
void | saveFile(String file)
Saves the content of this part to the specified file. |
void | setContent(Object o, String type)
Sets the content of this part using the specified Java object and MIME
type. |
void | setContent(Multipart mp)
Sets the content of this part to be the specified multipart. |
void | setContentID(String cid)
Sets the Content-ID header field of this part. |
void | setContentLanguage(String[] languages)
Sets the Content-Language header of this part. |
void | setContentMD5(String md5)
Sets the Content-MD5 header field of this part. |
void | setDataHandler(DataHandler dh)
Sets the content of this part using the specified data handler. |
void | setDescription(String description)
Sets the Content-Description header field for this part.
|
void | setDescription(String description, String charset)
Sets the Content-Description header field for this part.
|
void | setDisposition(String disposition)
Sets the Content-Disposition header field of this part. |
void | setFileName(String filename)
Sets the filename associated with this body part. |
void | setHeader(String name, String value)
Sets the specified header. |
void | setText(String text)
Sets the content of this part using the specified text, and with a
MIME type of "text/plain".
|
void | setText(String text, String charset)
Sets the content of this part using the specified text, and with a
MIME type of "text/plain".
|
void | setText(String text, String charset, String subtype)
Sets the content of this part using the specified text, and with a
text MIME type of the specified subtype.
|
protected void | updateHeaders()
Updates the headers of this part, based on the content. |
void | writeTo(OutputStream os)
Writes this body part to the specified stream in RFC 822 format. |
Parameters: is the input stream
Parameters: headers the header content the byte content of this part
Parameters: name the header name value the header value
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Parameters: file the file
Since: JavaMail 1.4
Parameters: file the file
Since: JavaMail 1.4
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
Throws: IOException if an error occurred in the data handler layer
null
if
this header is not available.If the Content-Description field is encoded as per RFC 2047, it is decoded and converted into Unicode.
null
if the header is not available.This method returns the value of the "filename" parameter from the Content-Disposition header field. If the latter is not available, it returns the value of the "name" parameter from the Content-Type header field.
Parameters: name the header name
null
, only the first header is
returned.Parameters: name the header name delimiter the delimiter
Throws: IOException if an error occurs in the data handler layer
Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
If the subtype of mimeType
is the special character '*',
the subtype is ignored during the comparison.
Parameters: name the header name
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Parameters: file the file
Since: JavaMail 1.4
Parameters: file the file
Since: JavaMail 1.4
Parameters: o the content object type the MIME type of the object
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Parameters: mp the multipart content
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Since: JavaMail 1.3
Parameters: languages the array of language tags
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
If description
contains non US-ASCII characters, it will
be encoded using the platform default charset.
Parameters: description the content description
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
If description
contains non US-ASCII characters, it will
be encoded using the specified charset.
Parameters: description the content description charset the charset used for encoding
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Parameters: name the header name value the header value
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
If the text contains non US-ASCII characters, it will be encoded using the platform default charset.
Parameters: text the text content
If the text contains non US-ASCII characters, it will be encoded using the specified charset.
Parameters: text the text content charset the charset used for any encoding
If the text contains non US-ASCII characters, it will be encoded using the specified charset.
Parameters: text the text content charset the charset used for any encoding subtype the MIME text subtype (e.g. "plain", "html")
Since: JavaMail 1.4
Throws: IllegalWriteException if the underlying implementation does not support modification IllegalStateException if this body part is obtained from a READ_ONLY folder
Throws: IOException if an error occurs writing to the stream or in the data handler layer