KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > server > web > MimeBodyPartDataSource


1 /***
2 * jwma Java WebMail
3 * Copyright (c) 2001 Dieter Wimberger
4 *
5 * jwma is free software; you can distribute and use this source
6 * under the terms of the BSD-style license received along with
7 * the distribution.
8 ***/

9 package org.lucane.server.web;
10
11 import java.io.ByteArrayInputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.InputStream JavaDoc;
14 import java.io.OutputStream JavaDoc;
15
16 import javax.activation.DataSource JavaDoc;
17
18 /**
19  * Class that implements a MimeBodyPartDataSource.
20  *
21  * It implements <code>DataSource</code> for handling
22  * with the Mail API (or other JAF aware) classes.
23  *
24  * @author Dieter Wimberger
25  * @version 0.9.5 04/05/2001
26  */

27 public class MimeBodyPartDataSource
28     implements DataSource JavaDoc {
29
30     //instance attributes
31
private String JavaDoc m_Type;
32     private String JavaDoc m_Name;
33     private byte[] m_Data;
34
35     /**
36      * Constructs a <code>MimeBodyPartDataSource</code>
37      * instance.
38      *
39      * @param type the content type of the constructed instance
40      * as <code>String</code>.
41      * @param name the name of the constructed instance
42      * as <code>String</code>.
43      * @param data the data of the constructed instance as
44      * <code>byte[]</code>.
45      *
46      * @return the newly constructed <code>MimeBodyPartDataSource
47      * </code>.
48      */

49      public MimeBodyPartDataSource(
50         String JavaDoc type, String JavaDoc name,byte[] data) {
51         
52         m_Type=type;
53         m_Name=name;
54         m_Data=data;
55      }//constructore
56

57     /**
58      * Returns the content type of this instance as
59      * <code>String</code>.
60      * <p>(DataSource implementation)
61      *
62      * @return the content type as <code>String</code>
63      */

64      public String JavaDoc getContentType(){
65         return m_Type;
66      }//getContentType
67

68     /**
69      * Returns the name of this instance as <code>String</code>.
70      * <p>(DataSource implementation)
71      *
72      * @return the name as <code>String</code>
73      */

74      public String JavaDoc getName(){
75         return m_Name;
76      }//getName
77

78     /**
79      * Returns the data of this instance as <code>
80      * InputStream</code>.
81      * <p>(DataSource implementation); wraps the data
82      * into a <code>ByteArrayInputStream</code>.
83      *
84      * @return the data of this instance as
85      * <code>InputStream</code>.
86      * @throws IOException if impossible.
87      */

88      public InputStream JavaDoc getInputStream()
89             throws IOException JavaDoc {
90             
91         return new ByteArrayInputStream JavaDoc(m_Data);
92      }//getInputStream
93

94     /**
95      * Throws an IOException in this implementation, because
96      * this instance represents a read-only <code>DataSource</code>.
97      * <p>(DataSource implementation)
98      *
99      * @return an <code>OutputStream</code> instance for writing
100      * to this <code>DataSource</code>.
101      * @throws IOException if impossible.
102      */

103      public OutputStream JavaDoc getOutputStream()
104             throws IOException JavaDoc {
105     
106         throw new IOException JavaDoc(
107             "Not supported."
108         );
109      }//getOutputStream
110

111 }//class MimeBodyPartDataSource
112
Popular Tags