001: /***
002: * jwma Java WebMail
003: * Copyright (c) 2000-2003 jwma team
004: *
005: * jwma is free software; you can distribute and use this source
006: * under the terms of the BSD-style license received along with
007: * the distribution.
008: ***/package dtw.webmail.util;
009:
010: import java.io.*;
011: import javax.mail.*;
012: import javax.mail.internet.*;
013: import javax.activation.*;
014:
015: /**
016: * Class that implements a MimeBodyPartDataSource.
017: *
018: * It implements <tt>DataSource</tt> for handling
019: * with the Mail API (or other JAF aware) classes.
020: *
021: * @author Dieter Wimberger
022: * @version 0.9.7 07/02/2003
023: */
024: public class MimeBodyPartDataSource implements DataSource {
025:
026: //instance attributes
027: private String m_Type;
028: private String m_Name;
029: private byte[] m_Data;
030:
031: /**
032: * Constructs a <tt>MimeBodyPartDataSource</tt>
033: * instance.
034: *
035: * @param type the content type of the constructed instance
036: * as <tt>String</tt>.
037: * @param name the name of the constructed instance
038: * as <tt>String</tt>.
039: * @param data the data of the constructed instance as
040: * <tt>byte[]</tt>.
041: *
042: * @return the newly constructed <tt>MimeBodyPartDataSource
043: * </tt>.
044: */
045: public MimeBodyPartDataSource(String type, String name, byte[] data) {
046:
047: m_Type = type;
048: m_Name = name;
049: m_Data = data;
050: }//constructore
051:
052: /**
053: * Returns the content type of this instance as
054: * <tt>String</tt>.
055: * <p>(DataSource implementation)
056: *
057: * @return the content type as <tt>String</tt>
058: */
059: public String getContentType() {
060: return m_Type;
061: }//getContentType
062:
063: /**
064: * Returns the name of this instance as <tt>String</tt>.
065: * <p>(DataSource implementation)
066: *
067: * @return the name as <tt>String</tt>
068: */
069: public String getName() {
070: return m_Name;
071: }//getName
072:
073: /**
074: * Returns the data of this instance as <tt>
075: * InputStream</tt>.
076: * <p>(DataSource implementation); wraps the data
077: * into a <tt>ByteArrayInputStream</tt>.
078: *
079: * @return the data of this instance as
080: * <tt>InputStream</tt>.
081: * @throws IOException if impossible.
082: */
083: public InputStream getInputStream() throws IOException {
084:
085: return new ByteArrayInputStream(m_Data);
086: }//getInputStream
087:
088: /**
089: * Throws an IOException in this implementation, because
090: * this instance represents a read-only <tt>DataSource</tt>.
091: * <p>(DataSource implementation)
092: *
093: * @return an <tt>OutputStream</tt> instance for writing
094: * to this <tt>DataSource</tt>.
095: * @throws IOException if impossible.
096: */
097: public OutputStream getOutputStream() throws IOException {
098:
099: throw new IOException("Not supported.");
100: }//getOutputStream
101:
102: }//class MimeBodyPartDataSource
|