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