javax.mail.util
Class ByteArrayDataSource

java.lang.Object
  extended by javax.mail.util.ByteArrayDataSource
All Implemented Interfaces:
DataSource

public class ByteArrayDataSource
extends Object
implements DataSource

An activation DataSource object that sources the data from a byte[] array.

Version:
$Rev: 467553 $ $Date: 2006-10-25 00:01:51 -0400 (Wed, 25 Oct 2006) $

Constructor Summary
ByteArrayDataSource(byte[] data, String type)
          Create a ByteArrayDataSource directly from a byte array.
ByteArrayDataSource(InputStream in, String type)
          Create a ByteArrayDataSource from an input stream.
ByteArrayDataSource(String data, String type)
          Create a ByteArrayDataSource from a string value.
 
Method Summary
 String getContentType()
          Get the MIME content type information for this DataSource.
 InputStream getInputStream()
          Create an input stream for this data.
 String getName()
          Retrieve the DataSource name.
 OutputStream getOutputStream()
          Open an output stream for the DataSource.
 void setName(String name)
          Set a new DataSource name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayDataSource

public ByteArrayDataSource(InputStream in,
                           String type)
                    throws IOException
Create a ByteArrayDataSource from an input stream.

Parameters:
in - The source input stream.
type - The MIME-type of the data.
Throws:
IOException

ByteArrayDataSource

public ByteArrayDataSource(byte[] data,
                           String type)
Create a ByteArrayDataSource directly from a byte array.

Parameters:
data - The source byte array (not copied).
type - The content MIME-type.

ByteArrayDataSource

public ByteArrayDataSource(String data,
                           String type)
                    throws IOException
Create a ByteArrayDataSource from a string value. If the type information includes a charset parameter, that charset is used to extract the bytes. Otherwise, the default Java char set is used.

Parameters:
data - The source data string.
type - The MIME type information.
Throws:
IOException
Method Detail

getInputStream

public InputStream getInputStream()
                           throws IOException
Create an input stream for this data. A new input stream is created each time.

Specified by:
getInputStream in interface DataSource
Returns:
An InputStream for reading the encapsulated data.
Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Open an output stream for the DataSource. This is not supported by this DataSource, so an IOException is always throws.

Specified by:
getOutputStream in interface DataSource
Returns:
Nothing...an IOException is always thrown.
Throws:
IOException

getContentType

public String getContentType()
Get the MIME content type information for this DataSource.

Specified by:
getContentType in interface DataSource
Returns:
The MIME content type string.

getName

public String getName()
Retrieve the DataSource name. If not explicitly set, this returns "".

Specified by:
getName in interface DataSource
Returns:
The currently set DataSource name.

setName

public void setName(String name)
Set a new DataSource name.

Parameters:
name - The new name.


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