public class

ByteArrayDataSource

extends Object
implements DataSource
java.lang.Object
   ↳ com.google.code.javax.mail.util.ByteArrayDataSource

Class Overview

A DataSource backed by a byte array. The byte array may be passed in directly, or may be initialized from an InputStream or a String.

Summary

Fields
private byte[] data
private int len
private String name
private String type
Public Constructors
ByteArrayDataSource(InputStream is, String type)
Create a ByteArrayDataSource with data from the specified InputStream and with the specified MIME type.
ByteArrayDataSource(byte[] data, String type)
Create a ByteArrayDataSource with data from the specified byte array and with the specified MIME type.
ByteArrayDataSource(String data, String type)
Create a ByteArrayDataSource with data from the specified String and with the specified MIME type.
Public Methods
String getContentType()
Get the MIME content type of the data.
InputStream getInputStream()
Return an InputStream for the data.
String getName()
Get the name of the data.
OutputStream getOutputStream()
Return an OutputStream for the data.
void setName(String name)
Set the name of the data.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.code.javax.activation.DataSource

Fields

private byte[] data

private int len

private String name

private String type

Public Constructors

public ByteArrayDataSource (InputStream is, String type)

Create a ByteArrayDataSource with data from the specified InputStream and with the specified MIME type. The InputStream is read completely and the data is stored in a byte array.

Parameters
is The InputStream
type The MIME type
Throws
IOException errors reading the stream

public ByteArrayDataSource (byte[] data, String type)

Create a ByteArrayDataSource with data from the specified byte array and with the specified MIME type.

Parameters
data The data
type The MIME type

public ByteArrayDataSource (String data, String type)

Create a ByteArrayDataSource with data from the specified String and with the specified MIME type. The MIME type should include a charset parameter specifying the charset to be used for the string. If the parameter is not included, the default charset is used.

Parameters
data The String
type The MIME type
Throws
IOException errors reading the String

Public Methods

public String getContentType ()

Get the MIME content type of the data.

Returns
  • the MIME type

public InputStream getInputStream ()

Return an InputStream for the data. Note that a new stream is returned each time this method is called.

Returns
  • the InputStream
Throws
IOException if no data has been set

public String getName ()

Get the name of the data. By default, an empty string ("") is returned.

Returns
  • the name of this data

public OutputStream getOutputStream ()

Return an OutputStream for the data. Writing the data is not supported; an IOException is always thrown.

Returns
  • an OutputStream
Throws
IOException always

public void setName (String name)

Set the name of the data.

Parameters
name The name of this data