1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.email.transformers; |
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 | |
import org.apache.commons.io.output.ByteArrayOutputStream; |
17 | |
|
18 | |
public class PlainTextDataSource implements DataSource |
19 | |
{ |
20 | |
public static final String CONTENT_TYPE = "text/plain"; |
21 | |
|
22 | |
private final String name; |
23 | |
private byte[] data; |
24 | |
private ByteArrayOutputStream os; |
25 | |
|
26 | |
|
27 | |
public PlainTextDataSource(String name, String data) |
28 | 0 | { |
29 | 0 | this.name = name; |
30 | 0 | this.data = data == null ? null : data.getBytes(); |
31 | 0 | os = new ByteArrayOutputStream(); |
32 | 0 | } |
33 | |
|
34 | |
public String getName() |
35 | |
{ |
36 | 0 | return name; |
37 | |
} |
38 | |
|
39 | |
public String getContentType() |
40 | |
{ |
41 | 0 | return CONTENT_TYPE; |
42 | |
} |
43 | |
|
44 | |
public InputStream getInputStream() throws IOException |
45 | |
{ |
46 | 0 | if (os.size() != 0) |
47 | |
{ |
48 | 0 | data = os.toByteArray(); |
49 | |
} |
50 | 0 | return new ByteArrayInputStream(data == null ? new byte[0] : data); |
51 | |
} |
52 | |
|
53 | |
public OutputStream getOutputStream() throws IOException |
54 | |
{ |
55 | 0 | if (os.size() != 0) |
56 | |
{ |
57 | 0 | data = os.toByteArray(); |
58 | |
} |
59 | 0 | return new ByteArrayOutputStream(); |
60 | |
} |
61 | |
|
62 | |
} |