FileDocCategorySizeDatePackage
MailDataSource.javaAPI DocApache James 2.3.14177Fri Jan 12 12:56:30 GMT 2007org.apache.james.transport.mailets.listservcommands

MailDataSource

public class MailDataSource extends Object implements DataSource
MailDataSource implements a typed DataSource from : an InputStream, a byte array, and a string This is used from {@link BaseCommand#generateMail}
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0

Fields Summary
protected static final int
DEFAULT_BUF_SIZE
protected static final String
DEFAULT_ENCODING
protected static final String
DEFAULT_NAME
protected byte[]
data
protected String
contentType
Constructors Summary
public MailDataSource(InputStream inputStream, String contentType)
Create a datasource from an input stream

 // content-type

                
           
        this.contentType = contentType;

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        copyStream(inputStream, baos);
        data = baos.toByteArray();
    
public MailDataSource(byte[] data, String contentType)
Create a datasource from a byte array

        this.contentType = contentType;
        this.data = data;
    
public MailDataSource(String data, String contentType)
Create a datasource from a String

        this.contentType = contentType;
        this.data = data.getBytes(DEFAULT_ENCODING);
    
Methods Summary
protected static intcopyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)

        inputStream = new BufferedInputStream(inputStream);
        outputStream = new BufferedOutputStream(outputStream);

        byte[] bbuf = new byte[DEFAULT_BUF_SIZE];
        int len;
        int totalBytes = 0;
        while ((len = inputStream.read(bbuf)) != -1) {
            outputStream.write(bbuf, 0, len);
            totalBytes += len;
        }
        outputStream.flush();
        return totalBytes;
    
public java.lang.StringgetContentType()
returns the contentType for this data source

        return contentType;
    
public java.io.InputStreamgetInputStream()
returns the inputStream

        if (data == null)
            throw new IOException("no data");
        return new ByteArrayInputStream(data);
    
public java.lang.StringgetName()
returns a static moniker

        return DEFAULT_NAME;
    
public java.io.OutputStreamgetOutputStream()
Not implemented

        throw new IOException("getOutputStream() isn't implemented");