1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.message.ds; |
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 | 0 | protected String contentType = "text/plain"; |
24 | 0 | protected String name = "StringDataSource"; |
25 | |
|
26 | |
public StringDataSource(String payload) |
27 | |
{ |
28 | 0 | super(); |
29 | 0 | content = payload; |
30 | 0 | } |
31 | |
|
32 | |
public StringDataSource(String payload, String name) |
33 | |
{ |
34 | 0 | super(); |
35 | 0 | content = payload; |
36 | 0 | this.name = name; |
37 | 0 | } |
38 | |
|
39 | |
public StringDataSource(String content, String name, String contentType) |
40 | 0 | { |
41 | 0 | this.content = content; |
42 | 0 | this.contentType = contentType; |
43 | 0 | this.name = name; |
44 | 0 | } |
45 | |
|
46 | |
public InputStream getInputStream() throws IOException |
47 | |
{ |
48 | 0 | return new ByteArrayInputStream(content.getBytes()); |
49 | |
} |
50 | |
|
51 | |
public OutputStream getOutputStream() |
52 | |
{ |
53 | 0 | throw new UnsupportedOperationException("Read-only javax.activation.DataSource"); |
54 | |
} |
55 | |
|
56 | |
public String getContentType() |
57 | |
{ |
58 | 0 | return contentType; |
59 | |
} |
60 | |
|
61 | |
public String getName() |
62 | |
{ |
63 | 0 | return name; |
64 | |
} |
65 | |
} |
66 | |
|