Protomatter Software v1.1.8

com.protomatter.util
Class MIMEAttachment

java.lang.Object
  |
  +--com.protomatter.util.MIMEAttachment
All Implemented Interfaces:
java.io.Serializable

public class MIMEAttachment
extends java.lang.Object
implements java.io.Serializable

This class is used in conjunction with the MIMEMessage class to make a multipart MIME message. A MIMEAttachment enacpsulates a single attachment (i.e. an image, a document, etc). Attached binaries are encoded using the Base64 method.

See Also:
MIMEMessage, Serialized Form

Constructor Summary
MIMEAttachment()
          Create an empty attachment.
MIMEAttachment(java.lang.String type, java.lang.String description, byte[] data)
          Create a MIMEAttachment object with the given MIME type and description.
MIMEAttachment(java.lang.String type, java.lang.String description, byte[] data, boolean isBinary)
          Create a MIMEAttachment object with the given MIME content type and description.
MIMEAttachment(java.lang.String type, java.lang.String description, java.lang.String content)
          Create a MIMEAttachment object with the given MIME content type and description.
 
Method Summary
 byte[] getContent()
          Return the content.
 java.lang.String getHeader(java.lang.String headerName)
          Get a header value.
 java.util.Enumeration getHeaderNames()
          Get an Enumeration of the header names.
 java.lang.String getSubHeader(java.lang.String name, java.lang.String sub)
          Some headers (such as Content-Disposition) have multiple key="value" pairs associated with them.
 boolean isBinary()
          Is the content of the attachment ascii or binary?
 void removeHeader(java.lang.String headerName)
          Remove a header value.
 void setBinary(boolean b)
          Set the flag to indicate that the content of this attachment is binary.
 void setContent(byte[] content)
          Set the content of this attachment.
 void setContent(java.lang.String content)
          Set the content of this attachment.
 void setHeader(java.lang.String headerName, java.lang.String headerVal)
          Set a header value.
 void setHeaders(java.util.Hashtable headers)
          Set the headers.
 java.lang.String toString()
          Produces a chunk of text, including the encoded attachment object
 void write(java.io.PrintWriter w)
          Append the content of this attachment to the given StringBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MIMEAttachment

public MIMEAttachment(java.lang.String type,
                      java.lang.String description,
                      java.lang.String content)
Create a MIMEAttachment object with the given MIME content type and description. The content will not be encoded using Base64.

MIMEAttachment

public MIMEAttachment(java.lang.String type,
                      java.lang.String description,
                      byte[] data,
                      boolean isBinary)
Create a MIMEAttachment object with the given MIME content type and description. The content will be encoded using Base64 if the isBinary flag is true.

MIMEAttachment

public MIMEAttachment(java.lang.String type,
                      java.lang.String description,
                      byte[] data)
Create a MIMEAttachment object with the given MIME type and description. The content will be encoded using Base64.

MIMEAttachment

public MIMEAttachment()
Create an empty attachment.
Method Detail

setHeaders

public void setHeaders(java.util.Hashtable headers)
Set the headers. Keys and values in must be strings.

setBinary

public void setBinary(boolean b)
Set the flag to indicate that the content of this attachment is binary.

setContent

public void setContent(java.lang.String content)
Set the content of this attachment.

setContent

public void setContent(byte[] content)
Set the content of this attachment.

setHeader

public void setHeader(java.lang.String headerName,
                      java.lang.String headerVal)
Set a header value.

removeHeader

public void removeHeader(java.lang.String headerName)
Remove a header value.

getHeader

public java.lang.String getHeader(java.lang.String headerName)
Get a header value.

getSubHeader

public java.lang.String getSubHeader(java.lang.String name,
                                     java.lang.String sub)
Some headers (such as Content-Disposition) have multiple key="value" pairs associated with them. This method allows you to get at those values easily. For instance, to get the "filename" chunk of the "Content-Disposition" header, call getSubHeader("Content-Disposition", "filename"); If you call it with sub = "", it will retrieve the first value (which doesn't have a name)

toString

public java.lang.String toString()
Produces a chunk of text, including the encoded attachment object
Overrides:
toString in class java.lang.Object

write

public void write(java.io.PrintWriter w)
Append the content of this attachment to the given StringBuffer.

getContent

public byte[] getContent()
Return the content. If it's binary, it's a byte array of binary data, if it's ASCII, you can just call new String(attachmentgetContent()).

getHeaderNames

public java.util.Enumeration getHeaderNames()
Get an Enumeration of the header names.

isBinary

public boolean isBinary()
Is the content of the attachment ascii or binary?

Protomatter Software v1.1.8
Copyright 1998-2002 Nate Sammons

Protomatter Software v1.1.8 http://protomatter.sourceforge.net/1.1.8