1
2
3
4
5
6
7 package org.mule.util;
8
9 import java.io.ByteArrayInputStream;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.OutputStream;
13
14 import javax.activation.DataSource;
15
16 public class StringDataSource implements DataSource
17 {
18 protected String content;
19 protected String contentType = "text/plain";
20 protected String name = "StringDataSource";
21
22 public StringDataSource(String payload)
23 {
24 super();
25 content = payload;
26 }
27
28 public StringDataSource(String payload, String name)
29 {
30 super();
31 content = payload;
32 this.name = name;
33 }
34
35 public StringDataSource(String content, String name, String contentType)
36 {
37 this.content = content;
38 this.contentType = contentType;
39 this.name = name;
40 }
41
42 public InputStream getInputStream() throws IOException
43 {
44 return new ByteArrayInputStream(content.getBytes());
45 }
46
47 public OutputStream getOutputStream()
48 {
49 throw new UnsupportedOperationException("Read-only javax.activation.DataSource");
50 }
51
52 public String getContentType()
53 {
54 return contentType;
55 }
56
57 public String getName()
58 {
59 return name;
60 }
61 }
62