javax.mail.internet
Class MimeBodyPart

java.lang.Object
  extended by javax.mail.BodyPart
      extended by javax.mail.internet.MimeBodyPart
All Implemented Interfaces:
MimePart, Part
Direct Known Subclasses:
PreencodedMimeBodyPart

public class MimeBodyPart
extends BodyPart
implements MimePart

Version:
$Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $

Field Summary
protected  byte[] content
          This message's content (unless sourced from a SharedInputStream).
protected  InputStream contentStream
          If the data for this message was supplied by a SharedInputStream then this is another such stream representing the content of this message; if this field is non-null, then content will be null.
protected  DataHandler dh
          The DataHandler for this Message's content.
protected  InternetHeaders headers
          This message's headers.
 
Fields inherited from class javax.mail.BodyPart
parent
 
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
 
Constructor Summary
MimeBodyPart()
           
MimeBodyPart(InputStream in)
           
MimeBodyPart(InternetHeaders headers, byte[] content)
           
 
Method Summary
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
 void attachFile(File file)
          Attach a file to this body part from a File object.
 void attachFile(String file)
          Attach a file to this body part from a file name.
 Enumeration getAllHeaderLines()
           
 Enumeration getAllHeaders()
           
 Object getContent()
           
 String getContentID()
          Retrieve the value of the "Content-ID" header.
 String[] getContentLanguage()
           
 String getContentMD5()
           
protected  InputStream getContentStream()
           
 String getContentType()
           
 DataHandler getDataHandler()
           
 String getDescription()
           
 String getDisposition()
          Retrieve the message "Content-Disposition" header field.
 String getEncoding()
          Retrieves the current value of the "Content-Transfer-Encoding" header.
 String getFileName()
           
 String[] getHeader(String name)
           
 String getHeader(String name, String delimiter)
           
 InputStream getInputStream()
           
 int getLineCount()
           
 Enumeration getMatchingHeaderLines(String[] names)
           
 Enumeration getMatchingHeaders(String[] name)
           
 Enumeration getNonMatchingHeaderLines(String[] names)
           
 Enumeration getNonMatchingHeaders(String[] name)
           
 InputStream getRawInputStream()
           
 int getSize()
          Return the content size of this message.
 boolean isMimeType(String type)
          Tests to see if this message has a mime-type match with the given type name.
 void removeHeader(String name)
           
 void saveFile(File file)
          Save the body part content to a given target file.
 void saveFile(String file)
          Save the body part content to a given target file.
 void setContent(Multipart part)
           
 void setContent(Object content, String type)
           
 void setContentID(String cid)
           
 void setContentLanguage(String[] languages)
           
 void setContentMD5(String md5)
           
 void setDataHandler(DataHandler handler)
           
 void setDescription(String description)
           
 void setDescription(String description, String charset)
           
 void setDisposition(String disposition)
          Set a new dispostion value for the "Content-Disposition" field.
 void setFileName(String name)
           
 void setHeader(String name, String value)
           
 void setText(String text)
           
 void setText(String text, String charset)
           
 void setText(String text, String charset, String subtype)
           
protected  void updateHeaders()
           
 void writeTo(OutputStream out)
           
 
Methods inherited from class javax.mail.BodyPart
getParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dh

protected DataHandler dh
The DataHandler for this Message's content.


content

protected byte[] content
This message's content (unless sourced from a SharedInputStream).


contentStream

protected InputStream contentStream
If the data for this message was supplied by a SharedInputStream then this is another such stream representing the content of this message; if this field is non-null, then content will be null.


headers

protected InternetHeaders headers
This message's headers.

Constructor Detail

MimeBodyPart

public MimeBodyPart()

MimeBodyPart

public MimeBodyPart(InputStream in)
             throws MessagingException
Throws:
MessagingException

MimeBodyPart

public MimeBodyPart(InternetHeaders headers,
                    byte[] content)
             throws MessagingException
Throws:
MessagingException
Method Detail

getSize

public int getSize()
            throws MessagingException
Return the content size of this message. This is obtained either from the size of the content field (if available) or from the contentStream, IFF the contentStream returns a positive size. Returns -1 if the size is not available.

Specified by:
getSize in interface Part
Returns:
Size of the content in bytes.
Throws:
MessagingException

getLineCount

public int getLineCount()
                 throws MessagingException
Specified by:
getLineCount in interface Part
Throws:
MessagingException

getContentType

public String getContentType()
                      throws MessagingException
Specified by:
getContentType in interface Part
Throws:
MessagingException

isMimeType

public boolean isMimeType(String type)
                   throws MessagingException
Tests to see if this message has a mime-type match with the given type name.

Specified by:
isMimeType in interface Part
Parameters:
type - The tested type name.
Returns:
If this is a type match on the primary and secondare portion of the types.
Throws:
MessagingException

getDisposition

public String getDisposition()
                      throws MessagingException
Retrieve the message "Content-Disposition" header field. This value represents how the part should be represented to the user.

Specified by:
getDisposition in interface Part
Returns:
The string value of the Content-Disposition field.
Throws:
MessagingException

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Set a new dispostion value for the "Content-Disposition" field. If the new value is null, the header is removed.

Specified by:
setDisposition in interface Part
Parameters:
disposition - The new disposition value.
Throws:
MessagingException

getEncoding

public String getEncoding()
                   throws MessagingException
Retrieves the current value of the "Content-Transfer-Encoding" header. Returns null if the header does not exist.

Specified by:
getEncoding in interface MimePart
Returns:
The current header value or null.
Throws:
MessagingException

getContentID

public String getContentID()
                    throws MessagingException
Retrieve the value of the "Content-ID" header. Returns null if the header does not exist.

Specified by:
getContentID in interface MimePart
Returns:
The current header value or null.
Throws:
MessagingException

setContentID

public void setContentID(String cid)
                  throws MessagingException
Throws:
MessagingException

getContentMD5

public String getContentMD5()
                     throws MessagingException
Specified by:
getContentMD5 in interface MimePart
Throws:
MessagingException

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Specified by:
setContentMD5 in interface MimePart
Throws:
MessagingException

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Specified by:
getContentLanguage in interface MimePart
Throws:
MessagingException

setContentLanguage

public void setContentLanguage(String[] languages)
                        throws MessagingException
Specified by:
setContentLanguage in interface MimePart
Throws:
MessagingException

getDescription

public String getDescription()
                      throws MessagingException
Specified by:
getDescription in interface Part
Throws:
MessagingException

setDescription

public void setDescription(String description)
                    throws MessagingException
Specified by:
setDescription in interface Part
Throws:
MessagingException

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Throws:
MessagingException

getFileName

public String getFileName()
                   throws MessagingException
Specified by:
getFileName in interface Part
Throws:
MessagingException

setFileName

public void setFileName(String name)
                 throws MessagingException
Specified by:
setFileName in interface Part
Throws:
MessagingException

getInputStream

public InputStream getInputStream()
                           throws MessagingException,
                                  IOException
Specified by:
getInputStream in interface Part
Throws:
MessagingException
IOException

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Throws:
MessagingException

getRawInputStream

public InputStream getRawInputStream()
                              throws MessagingException
Throws:
MessagingException

getDataHandler

public DataHandler getDataHandler()
                           throws MessagingException
Specified by:
getDataHandler in interface Part
Throws:
MessagingException

getContent

public Object getContent()
                  throws MessagingException,
                         IOException
Specified by:
getContent in interface Part
Throws:
MessagingException
IOException

setDataHandler

public void setDataHandler(DataHandler handler)
                    throws MessagingException
Specified by:
setDataHandler in interface Part
Throws:
MessagingException

setContent

public void setContent(Object content,
                       String type)
                throws MessagingException
Specified by:
setContent in interface Part
Throws:
MessagingException

setText

public void setText(String text)
             throws MessagingException
Specified by:
setText in interface MimePart
Specified by:
setText in interface Part
Throws:
MessagingException

setText

public void setText(String text,
                    String charset)
             throws MessagingException
Specified by:
setText in interface MimePart
Throws:
MessagingException

setText

public void setText(String text,
                    String charset,
                    String subtype)
             throws MessagingException
Specified by:
setText in interface MimePart
Throws:
MessagingException

setContent

public void setContent(Multipart part)
                throws MessagingException
Specified by:
setContent in interface Part
Throws:
MessagingException

writeTo

public void writeTo(OutputStream out)
             throws IOException,
                    MessagingException
Specified by:
writeTo in interface Part
Throws:
IOException
MessagingException

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Specified by:
getHeader in interface Part
Throws:
MessagingException

getHeader

public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
Specified by:
getHeader in interface MimePart
Throws:
MessagingException

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Specified by:
setHeader in interface Part
Throws:
MessagingException

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Specified by:
addHeader in interface Part
Throws:
MessagingException

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Specified by:
removeHeader in interface Part
Throws:
MessagingException

getAllHeaders

public Enumeration getAllHeaders()
                          throws MessagingException
Specified by:
getAllHeaders in interface Part
Throws:
MessagingException

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] name)
                               throws MessagingException
Specified by:
getMatchingHeaders in interface Part
Throws:
MessagingException

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] name)
                                  throws MessagingException
Specified by:
getNonMatchingHeaders in interface Part
Throws:
MessagingException

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Specified by:
addHeaderLine in interface MimePart
Throws:
MessagingException

getAllHeaderLines

public Enumeration getAllHeaderLines()
                              throws MessagingException
Specified by:
getAllHeaderLines in interface MimePart
Throws:
MessagingException

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Specified by:
getMatchingHeaderLines in interface MimePart
Throws:
MessagingException

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Specified by:
getNonMatchingHeaderLines in interface MimePart
Throws:
MessagingException

updateHeaders

protected void updateHeaders()
                      throws MessagingException
Throws:
MessagingException

attachFile

public void attachFile(File file)
                throws IOException,
                       MessagingException
Attach a file to this body part from a File object.

Parameters:
file - The source File object.
Throws:
IOException
MessagingException

attachFile

public void attachFile(String file)
                throws IOException,
                       MessagingException
Attach a file to this body part from a file name.

Parameters:
file - The source file name.
Throws:
IOException
MessagingException

saveFile

public void saveFile(File file)
              throws IOException,
                     MessagingException
Save the body part content to a given target file.

Parameters:
file - The File object used to store the information.
Throws:
IOException
MessagingException

saveFile

public void saveFile(String file)
              throws IOException,
                     MessagingException
Save the body part content to a given target file.

Parameters:
file - The file name used to store the information.
Throws:
IOException
MessagingException


Copyright © 2006 Apache Software Foundation. All Rights Reserved.