org.clapper.util.mail
Class StringDataSource

java.lang.Object
  extended by org.clapper.util.mail.StringDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class StringDataSource
extends java.lang.Object
implements javax.activation.DataSource

StringDataSource implements the Java Activation Framework's DataSource interface to enable using a string as a data source. It is used primarily within the EmailMessage class to handle MIME attachments stored within a String or a StringBuffer.

Version:
$Revision: 6735 $
Author:
Copyright © 2004-2007 Brian M. Clapper

Constructor Summary
StringDataSource(java.lang.String s, java.lang.String mimeType, java.lang.String name)
          Create a new StringDataSource object.
 
Method Summary
 java.lang.String getContentType()
          Get the content type (i.e., the MIME type) associated with the underlying string's content.
 java.io.InputStream getInputStream()
          Get a new InputStream object that will read from this object's string buffer.
 java.lang.String getName()
          Get the name associated with the underlying string's content.
 java.io.OutputStream getOutputStream()
          According to the documentation for the DataSource interface, this method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringDataSource

public StringDataSource(java.lang.String s,
                        java.lang.String mimeType,
                        java.lang.String name)
Create a new StringDataSource object.

Parameters:
s - The string from which to read
mimeType - The MIME type (or content type) to associate with the contents of the string. If this parameter is null, it defaults to "application/octet-stream".
name - The name to associate with the content. For an email attachment, this parameter is typically used to name the attachment. If this parameter is null, a name will be generated.
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get a new InputStream object that will read from this object's string buffer.

Specified by:
getInputStream in interface javax.activation.DataSource
Returns:
The InputStream.
Throws:
java.io.IOException - On error.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
According to the documentation for the DataSource interface, this method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so. Since there's no output destination associated with a string, this implementation of getOutputStream() automatically throws an exception.

Specified by:
getOutputStream in interface javax.activation.DataSource
Returns:
Nothing.
Throws:
java.io.IOException - Always.

getContentType

public java.lang.String getContentType()
Get the content type (i.e., the MIME type) associated with the underlying string's content.

Specified by:
getContentType in interface javax.activation.DataSource
Returns:
The content type.

getName

public java.lang.String getName()
Get the name associated with the underlying string's content.

Specified by:
getName in interface javax.activation.DataSource
Returns:
The name.


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.