| 
 | Java EE 5 SDK | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Part
The Part interface is the common base interface for 
 Messages and BodyParts. 
Part consists of a set of attributes and a "Content".
Attributes:
The JavaMail API defines a set of standard Part attributes that are considered to be common to most existing Mail systems. These attributes have their own settor and gettor methods. Mail systems may support other Part attributes as well, these are represented as name-value pairs where both the name and value are Strings.
Content:
 The data type of the "content" is returned by
 the getContentType() method. The MIME typing system
 is used to name data types. 
The "content" of a Part is available in various formats:
getDataHandler() method.
 The "content" of a Part is also available through a 
 javax.activation.DataHandler object. The DataHandler 
 object allows clients to discover the operations available on the
 content, and to instantiate the appropriate component to perform
 those operations. 
 getInputStream() method.
 Any mail-specific encodings are decoded before this stream is returned.
 getContent() method.
 This method returns the "content" as a Java object.
 The returned object is of course dependent on the content
 itself. In particular, a "multipart" Part's content is always a 
 Multipart or subclass thereof. That is, getContent() on a 
 "multipart" type Part will always return a Multipart (or subclass) object.
 writeTo() method that streams
 out its bytestream in mail-safe form suitable for transmission. 
 This bytestream is typically an aggregation of the Part attributes
 and its content's bytestream. Message and BodyPart implement the Part interface. Note that in MIME parlance, Part models an Entity (RFC 2045, Section 2.4).
| Field Summary | |
|---|---|
| static String | ATTACHMENTThis part should be presented as an attachment. | 
| static String | INLINEThis part should be presented inline. | 
| Method Summary | |
|---|---|
|  void | addHeader(String header_name,
 String header_value)Add this value to the existing values for this header_name. | 
|  Enumeration | getAllHeaders()Return all the headers from this part as an Enumeration of Header objects. | 
|  Object | getContent()Return the content as a Java object. | 
|  String | getContentType()Returns the Content-Type of the content of this part. | 
|  DataHandler | getDataHandler()Return a DataHandler for the content within this part. | 
|  String | getDescription()Return a description String for this part. | 
|  String | getDisposition()Return the disposition of this part. | 
|  String | getFileName()Get the filename associated with this part, if possible. | 
|  String[] | getHeader(String header_name)Get all the headers for this header name. | 
|  InputStream | getInputStream()Return an input stream for this part's "content". | 
|  int | getLineCount()Return the number of lines in the content of this part. | 
|  Enumeration | getMatchingHeaders(String[] header_names)Return matching headers from this part as an Enumeration of Header objects. | 
|  Enumeration | getNonMatchingHeaders(String[] header_names)Return non-matching headers from this envelope as an Enumeration of Header objects. | 
|  int | getSize()Return the size of the content of this part in bytes. | 
|  boolean | isMimeType(String mimeType)Is this Part of the specified MIME type? | 
|  void | removeHeader(String header_name)Remove all headers with this name. | 
|  void | setContent(Multipart mp)This method sets the given Multipart object as this message's content. | 
|  void | setContent(Object obj,
 String type)A convenience method for setting this part's content. | 
|  void | setDataHandler(DataHandler dh)This method provides the mechanism to set this part's content. | 
|  void | setDescription(String description)Set a description String for this part. | 
|  void | setDisposition(String disposition)Set the disposition of this part. | 
|  void | setFileName(String filename)Set the filename associated with this part, if possible. | 
|  void | setHeader(String header_name,
 String header_value)Set the value for this header_name. | 
|  void | setText(String text)A convenience method that sets the given String as this part's content with a MIME type of "text/plain". | 
|  void | writeTo(OutputStream os)Output a bytestream for this Part. | 
| Field Detail | 
|---|
static final String ATTACHMENT
static final String INLINE
| Method Detail | 
|---|
int getSize() throws MessagingException
Note that the size may not be an exact measure of the content size and may or may not account for any transfer encoding of the content. The size is appropriate for display in a user interface to give the user a rough idea of the size of this part.
MessagingExceptionint getLineCount() throws MessagingException
MessagingExceptionString getContentType() throws MessagingException
The MIME typing system is used to name Content-types.
MessagingExceptionDataHandlerboolean isMimeType(String mimeType) throws MessagingException
primaryType and 
 subType.
 The parameters of the content types are ignored. 
 For example, this method will return true when
 comparing a Part of content type "text/plain"
 with "text/plain; charset=foobar". 
 If the subType of mimeType is the
 special character '*', then the subtype is ignored during the
 comparison.
MessagingExceptionString getDisposition() throws MessagingException
String disp = part.getDisposition(); if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) // treat as attachment if not first part
MessagingExceptionATTACHMENT, 
INLINE, 
getFileName()void setDisposition(String disposition) throws MessagingException
disposition - disposition of this part
MessagingException
IllegalWriteException - if the underlying implementation
 does not support modification of this header
IllegalStateException - if this Part is obtained
 from a READ_ONLY folderATTACHMENT, 
INLINE, 
setFileName(java.lang.String)String getDescription() throws MessagingException
MessagingExceptionvoid setDescription(String description) throws MessagingException
description - description of this part
MessagingException
IllegalWriteException - if the underlying implementation
 does not support modification of this header
IllegalStateException - if this Part is obtained
 from a READ_ONLY folderString getFileName() throws MessagingException
MessagingExceptionvoid setFileName(String filename) throws MessagingException
filename - Filename to associate with this part
IllegalWriteException - if the underlying implementation
 does not support modification of this header
IllegalStateException - if this Part is obtained
 from a READ_ONLY folder
MessagingExceptionInputStream getInputStream() throws IOException, MessagingException
 This is typically a convenience method that just invokes
 the DataHandler's getInputStream() method.
IOException - this is typically thrown by the 
 DataHandler. Refer to the documentation for 
 javax.activation.DataHandler for more details.
MessagingExceptiongetDataHandler(), 
DataHandler.getInputStream()DataHandler getDataHandler() throws MessagingException
MessagingExceptionObject getContent() throws IOException, MessagingException
This is a convenience method that just invokes the DataHandler's getContent() method
MessagingException
IOException - this is typically thrown by the 
 DataHandler. Refer to the documentation for 
 javax.activation.DataHandler for more details.DataHandler.getContent()void setDataHandler(DataHandler dh) throws MessagingException
dh - The DataHandler for the content.
MessagingException
IllegalWriteException - if the underlying implementation
 does not support modification of existing values
IllegalStateException - if this Part is obtained
 from a READ_ONLY foldervoid setContent(Object obj, String type) throws MessagingException
 Note that a DataContentHandler class for the specified type should 
 be available to the JavaMail implementation for this to work right.
 i.e., to do setContent(foobar, "application/x-foobar"),
 a DataContentHandler for "application/x-foobar" should be installed.
 Refer to the Java Activation Framework for more information.
obj - A java object.type - MIME type of this object.
IllegalWriteException - if the underlying implementation
 does not support modification of existing values
IllegalStateException - if this Part is obtained
 from a READ_ONLY folder
MessagingExceptionvoid setText(String text) throws MessagingException
text - The text that is the Message's content.
IllegalWriteException - if the underlying 
 implementation does not support modification of 
 existing values
IllegalStateException - if this Part is obtained
 from a READ_ONLY folder
MessagingExceptionvoid setContent(Multipart mp) throws MessagingException
mp - The multipart object that is the Message's content
IllegalWriteException - if the underlying 
 implementation does not support modification of 
 existing values
IllegalStateException - if this Part is obtained
 from a READ_ONLY folder
MessagingExceptionvoid writeTo(OutputStream os) throws IOException, MessagingException
Classes that implement the Part interface decide on the appropriate encoding algorithm to be used.
The bytestream is typically used for sending.
IOException - if an error occurs writing to the 
 stream or if an error is generated
 by the javax.activation layer.
MessagingException - if an error occurs fetching the
 data to be writtenDataHandler.writeTo(java.io.OutputStream)String[] getHeader(String header_name) throws MessagingException
null
 if no headers for this header name are available.
header_name - the name of this header
MessagingExceptionvoid setHeader(String header_name, String header_value) throws MessagingException
header_name - the name of this headerheader_value - the value for this header
MessagingException
IllegalWriteException - if the underlying 
 implementation does not support modification 
 of existing values
IllegalStateException - if this Part is 
 obtained from a READ_ONLY foldervoid addHeader(String header_name, String header_value) throws MessagingException
header_name - the name of this headerheader_value - the value for this header
MessagingException
IllegalWriteException - if the underlying 
 implementation does not support modification 
 of existing values
IllegalStateException - if this Part is 
 obtained from a READ_ONLY foldervoid removeHeader(String header_name) throws MessagingException
header_name - the name of this header
MessagingException
IllegalWriteException - if the underlying 
 implementation does not support modification 
 of existing values
IllegalStateException - if this Part is 
 obtained from a READ_ONLY folderEnumeration getAllHeaders() throws MessagingException
MessagingExceptionEnumeration getMatchingHeaders(String[] header_names) throws MessagingException
MessagingExceptionEnumeration getNonMatchingHeaders(String[] header_names) throws MessagingException
MessagingException| 
 | Java EE 5 SDK | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
Scripting on this page tracks web page traffic, but does not change the content in any way.