org.apache.commons.mail
Class ByteArrayDataSource

java.lang.Object
  extended by org.apache.commons.mail.ByteArrayDataSource
All Implemented Interfaces:
DataSource

public class ByteArrayDataSource
extends Object
implements DataSource

This class implements a typed DataSource from:
- an InputStream
- a byte array
- a String

Since:
1.0
Version:
$Id: ByteArrayDataSource.java 1420381 2012-12-11 20:18:05Z tn $
Author:
Colin Chalmers, Jon S. Stevens, Brett McLaughlin

Field Summary
static int BUFFER_SIZE
          Define the buffer size.
 
Constructor Summary
ByteArrayDataSource(byte[] data, String aType)
          Create a datasource from a byte array.
ByteArrayDataSource(InputStream aIs, String aType)
          Create a datasource from an input stream.
ByteArrayDataSource(String data, String aType)
          Create a datasource from a String.
 
Method Summary
 String getContentType()
          Get the content type.
 InputStream getInputStream()
          Get the input stream.
 String getName()
          Get the name.
 OutputStream getOutputStream()
          Get the OutputStream to write to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
Define the buffer size.

See Also:
Constant Field Values
Constructor Detail

ByteArrayDataSource

public ByteArrayDataSource(byte[] data,
                           String aType)
                    throws IOException
Create a datasource from a byte array.

Parameters:
data - A byte[].
aType - A String.
Throws:
IOException - IOException
Since:
1.0

ByteArrayDataSource

public ByteArrayDataSource(InputStream aIs,
                           String aType)
                    throws IOException
Create a datasource from an input stream.

Parameters:
aIs - An InputStream.
aType - A String.
Throws:
IOException - IOException
Since:
1.0

ByteArrayDataSource

public ByteArrayDataSource(String data,
                           String aType)
                    throws IOException
Create a datasource from a String. N.B. assumes the data string can be converted using the charset iso-8859-1.

Parameters:
data - A String.
aType - A String.
Throws:
IOException - IOException
Since:
1.0
Method Detail

getContentType

public String getContentType()
Get the content type.

Specified by:
getContentType in interface DataSource
Returns:
A String.
Since:
1.0

getInputStream

public InputStream getInputStream()
                           throws IOException
Get the input stream.

Specified by:
getInputStream in interface DataSource
Returns:
An InputStream.
Throws:
IOException - IOException
Since:
1.0

getName

public String getName()
Get the name.

Specified by:
getName in interface DataSource
Returns:
A String.
Since:
1.0

getOutputStream

public OutputStream getOutputStream()
Get the OutputStream to write to.

Specified by:
getOutputStream in interface DataSource
Returns:
An OutputStream
Since:
1.0


Copyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.