Java Reference
In-Depth Information
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
X-UIDL: 40fa8af2aca1a8c11994f4c56b792720
Status: RO
Content
Every part has content that can be represented as a sequence of bytes. For instance, in
a part that's a simple email message, the content is the body of the message. However,
in multipart messages, this content may itself contain other parts. The content of each
of these parts can be represented as a sequence of bytes. Furthermore, this sequence of
bytes may represent some more specific content type, such as a uuencoded GIF image
or a Base64-encoded WAV audio clip.
Reading the contents of the part
The Part interface declares two methods for determining a part's MIME content type.
The getContentType() method returns the MIME content type of the part as a string;
for example: text/plain; charset="us-ascii"; format="flowed" . It returns null
if the content type can't be determined:
public String getContentType () throws MessagingException
The isMimeType() method returns true if this part has the specified MIME type and
subtype. Additional parameters, such as charset, are ignored:
public boolean isMimeType ( String mimeType ) throws MessagingException
The Part interface also declares several methods that return the content as a variety of
different Java objects, including InputStream , String , DataHandler , and more. The
getInputStream() method returns an InputStream from which the part's content can
be read:
public InputStream getInputStream ()
throws IOException , MessagingException
If the part's content has been encoded in some way—for example, Base64-encoded—
then the InputStream reads the decoded content. The JavaMail API supports most
common encodings.
Another possibility is to request a DataHandler for the content with the getDataHan
dler() method. The DataHandler class comes from the Java Activation Framework. It
declares methods to help decide what to do with the content—for instance, by finding
the right Java bean or helper application to display the content:
public javax . activation . DataHandler getDataHandler ()
throws MessagingException
A third possibility is to request the content as an unspecified Java object using the
getContent() method:
Search WWH ::




Custom Search