javax.mail
Interface Part

All Known Subinterfaces:
MimePart
All Known Implementing Classes:
BodyPart, Message, MimeBodyPart, MimeMessage, PreencodedMimeBodyPart

public interface Part

Note: Parts are used in Collections so implementing classes must provide a suitable implementation of equals and hashCode.

Version:
$Rev: 578802 $ $Date: 2007-09-24 09:16:44 -0400 (Mon, 24 Sep 2007) $

Field Summary
static String ATTACHMENT
          This part should be presented as an attachment.
static String INLINE
          This part should be presented or rendered inline.
 
Method Summary
 void addHeader(String name, String value)
          Add this value to the existing headers with the given name.
 Enumeration getAllHeaders()
          Return all headers as an Enumeration of Header objects.
 Object getContent()
          Return a content object for this Part.
 String getContentType()
          Get the ContentType for this part, or null if the ContentType has not been set.
 DataHandler getDataHandler()
          Returns a DataHandler instance for the content with in the Part.
 String getDescription()
          Returns a description string for this Part.
 String getDisposition()
          Return the disposition of the part.
 String getFileName()
          Get a file name associated with this part.
 String[] getHeader(String name)
          Get all Headers for this header name.
 InputStream getInputStream()
          Return an InputStream for accessing the Part content.
 int getLineCount()
          Return the number of lines in the content, or -1 if the line count cannot be determined.
 Enumeration getMatchingHeaders(String[] names)
          Return all headers that match the list of names as an Enumeration of Header objects.
 Enumeration getNonMatchingHeaders(String[] names)
          Return an Enumeration of all Headers except those that match the names given in the exclusion list.
 int getSize()
          Return the size of this part, or -1 if the size cannot be reliably determined.
 boolean isMimeType(String mimeType)
          Tests if the part is of the specified MIME type.
 void removeHeader(String name)
          Remove all headers with the given name from the Part.
 void setContent(Multipart content)
           
 void setContent(Object content, String type)
          Set a content object for this part.
 void setDataHandler(DataHandler handler)
          Set a DataHandler for this part that defines the Part content.
 void setDescription(String description)
          Set a descriptive string for this part.
 void setDisposition(String disposition)
          Set the disposition for this Part.
 void setFileName(String name)
          Set a descriptive file name for this part.
 void setHeader(String name, String value)
          Sets a value for the given header.
 void setText(String content)
          Set the Part content as text.
 void writeTo(OutputStream out)
          Write the Part content out to the provided OutputStream as a byte stream using an encoding appropriate to the Part content.
 

Field Detail

ATTACHMENT

static final String ATTACHMENT
This part should be presented as an attachment.

See Also:
Constant Field Values

INLINE

static final String INLINE
This part should be presented or rendered inline.

See Also:
Constant Field Values
Method Detail

addHeader

void addHeader(String name,
               String value)
               throws MessagingException
Add this value to the existing headers with the given name. This method does not replace any headers that may already exist.

Parameters:
name - The name of the target header.
value - The value to be added to the header set.
Throws:
MessagingException

getAllHeaders

Enumeration getAllHeaders()
                          throws MessagingException
Return all headers as an Enumeration of Header objects.

Returns:
An Enumeration containing all of the current Header objects.
Throws:
MessagingException

getContent

Object getContent()
                  throws IOException,
                         MessagingException
Return a content object for this Part. The content object type is dependent upon the DataHandler for the Part.

Returns:
A content object for this Part.
Throws:
IOException
MessagingException

getContentType

String getContentType()
                      throws MessagingException
Get the ContentType for this part, or null if the ContentType has not been set. The ContentType is expressed using the MIME typing system.

Returns:
The ContentType for this part.
Throws:
MessagingException

getDataHandler

DataHandler getDataHandler()
                           throws MessagingException
Returns a DataHandler instance for the content with in the Part.

Returns:
A DataHandler appropriate for the Part content.
Throws:
MessagingException

getDescription

String getDescription()
                      throws MessagingException
Returns a description string for this Part. Returns null if a description has not been set.

Returns:
The description string.
Throws:
MessagingException

getDisposition

String getDisposition()
                      throws MessagingException
Return the disposition of the part. The disposition determines how the part should be presented to the user. Two common disposition values are ATTACHMENT and INLINE.

Returns:
The current disposition value.
Throws:
MessagingException

getFileName

String getFileName()
                   throws MessagingException
Get a file name associated with this part. The file name is useful for presenting attachment parts as their original source. The file names are generally simple names without containing any directory information. Returns null if the filename has not been set.

Returns:
The string filename, if any.
Throws:
MessagingException

getHeader

String[] getHeader(String name)
                   throws MessagingException
Get all Headers for this header name. Returns null if no headers with the given name exist.

Parameters:
name - The target header name.
Returns:
An array of all matching header values, or null if the given header does not exist.
Throws:
MessagingException

getInputStream

InputStream getInputStream()
                           throws IOException,
                                  MessagingException
Return an InputStream for accessing the Part content. Any mail-related transfer encodings will be removed, so the data presented with be the actual part content.

Returns:
An InputStream for accessing the part content.
Throws:
IOException
MessagingException

getLineCount

int getLineCount()
                 throws MessagingException
Return the number of lines in the content, or -1 if the line count cannot be determined.

Returns:
The estimated number of lines in the content.
Throws:
MessagingException

getMatchingHeaders

Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Return all headers that match the list of names as an Enumeration of Header objects.

Parameters:
names - An array of names of the desired headers.
Returns:
An Enumeration of Header objects containing the matching headers.
Throws:
MessagingException

getNonMatchingHeaders

Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Return an Enumeration of all Headers except those that match the names given in the exclusion list.

Parameters:
names - An array of String header names that will be excluded from the return Enumeration set.
Returns:
An Enumeration of Headers containing all headers except for those named in the exclusion list.
Throws:
MessagingException

getSize

int getSize()
            throws MessagingException
Return the size of this part, or -1 if the size cannot be reliably determined. Note: the returned size does not take into account internal encodings, nor is it an estimate of how many bytes are required to transfer this part across a network. This value is intended to give email clients a rough idea of the amount of space that might be required to present the item.

Returns:
The estimated part size, or -1 if the size information cannot be determined.
Throws:
MessagingException

isMimeType

boolean isMimeType(String mimeType)
                   throws MessagingException
Tests if the part is of the specified MIME type. Only the primaryPart and subPart of the MIME type are used for the comparison; arguments are ignored. The wildcard value of "*" may be used to match all subTypes.

Parameters:
mimeType - The target MIME type.
Returns:
true if the part matches the input MIME type, false if it is not of the requested type.
Throws:
MessagingException

removeHeader

void removeHeader(String name)
                  throws MessagingException
Remove all headers with the given name from the Part.

Parameters:
name - The target header name used for removal.
Throws:
MessagingException

setContent

void setContent(Multipart content)
                throws MessagingException
Throws:
MessagingException

setContent

void setContent(Object content,
                String type)
                throws MessagingException
Set a content object for this part. Internally, the Part will use the MIME type encoded in the type argument to wrap the provided content object. In order for this to work properly, an appropriate DataHandler must be installed in the Java Activation Framework.

Parameters:
content - The content object.
type - The MIME type for the inserted content Object.
Throws:
MessagingException

setDataHandler

void setDataHandler(DataHandler handler)
                    throws MessagingException
Set a DataHandler for this part that defines the Part content. The DataHandler is used to access all Part content.

Parameters:
handler - The DataHandler instance.
Throws:
MessagingException

setDescription

void setDescription(String description)
                    throws MessagingException
Set a descriptive string for this part.

Parameters:
description - The new description.
Throws:
MessagingException

setDisposition

void setDisposition(String disposition)
                    throws MessagingException
Set the disposition for this Part.

Parameters:
disposition - The disposition string.
Throws:
MessagingException

setFileName

void setFileName(String name)
                 throws MessagingException
Set a descriptive file name for this part. The name should be a simple name that does not include directory information.

Parameters:
name - The new name value.
Throws:
MessagingException

setHeader

void setHeader(String name,
               String value)
               throws MessagingException
Sets a value for the given header. This operation will replace all existing headers with the given name.

Parameters:
name - The name of the target header.
value - The new value for the indicated header.
Throws:
MessagingException

setText

void setText(String content)
             throws MessagingException
Set the Part content as text. This is a convenience method that sets the content to a MIME type of "text/plain".

Parameters:
content - The new text content, as a String object.
Throws:
MessagingException

writeTo

void writeTo(OutputStream out)
             throws IOException,
                    MessagingException
Write the Part content out to the provided OutputStream as a byte stream using an encoding appropriate to the Part content.

Parameters:
out - The target OutputStream.
Throws:
IOException
MessagingException


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.