KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > util > StreamDataSource


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.util;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.OutputStream JavaDoc;
22
23 import javax.activation.DataSource JavaDoc;
24
25 /**
26  * Stream DataSource for Mail and message attachments .
27  * @author <a HREF="mailto:gnodet@logicblaze.com"> Guillaume Nodet</a>
28  * @since 3.0
29  */

30 public class StreamDataSource implements DataSource JavaDoc {
31
32     private InputStream JavaDoc in;
33     private String JavaDoc contentType;
34     private String JavaDoc name;
35     
36     public StreamDataSource(InputStream JavaDoc in) {
37         this(in, null, null);
38     }
39
40     public StreamDataSource(InputStream JavaDoc in, String JavaDoc contentType) {
41         this(in, contentType, null);
42     }
43
44     public StreamDataSource(InputStream JavaDoc in, String JavaDoc contentType, String JavaDoc name) {
45         this.in = in;
46         this.contentType = contentType;
47         this.name = name;
48     }
49
50     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
51         if (in == null) throw new IOException JavaDoc("no data");
52         return in;
53     }
54
55     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
56         throw new IOException JavaDoc("getOutputStream() not supported");
57     }
58
59     public String JavaDoc getContentType() {
60         return contentType;
61     }
62
63     public String JavaDoc getName() {
64         return name;
65     }
66
67     public void setName(String JavaDoc name) {
68         this.name = name;
69     }
70
71     public void setContentType(String JavaDoc contentType) {
72         this.contentType = contentType;
73     }
74
75 }
76
Popular Tags