KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > attachments > ByteArrayDataSource


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

17 package org.apache.axis2.attachments;
18
19 import javax.activation.DataSource JavaDoc;
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
27  */

28 public class ByteArrayDataSource implements DataSource JavaDoc {
29
30     private byte[] data;
31
32     private String JavaDoc type;
33
34     public ByteArrayDataSource(byte[] data, String JavaDoc type) {
35         super();
36         this.data = data;
37         this.type = type;
38     }
39
40     public ByteArrayDataSource(byte[] data) {
41         super();
42         this.data = data;
43     }
44
45     public void setType(String JavaDoc type) {
46         this.type = type;
47     }
48
49     public String JavaDoc getContentType() {
50         if (type == null)
51             return "application/octet-stream";
52         else
53             return type;
54     }
55
56     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
57         return new ByteArrayInputStream JavaDoc(data);
58     }
59
60     public String JavaDoc getName() {
61
62         return "ByteArrayDataSource";
63     }
64
65     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
66         throw new IOException JavaDoc("Not Supported");
67     }
68 }
69
70
Popular Tags