01: package org.claros.commons.mail.models;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.FileNotFoundException;
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.io.OutputStream;
08:
09: import javax.activation.DataSource;
10:
11: /**
12: * @author Umut Gokbayrak
13: */
14: public class ByteArrayDataSource implements DataSource {
15: private byte[] bytes;
16: private String contentType, name;
17:
18: public ByteArrayDataSource(byte[] bytes, String contentType,
19: String name) {
20: this .bytes = bytes;
21: if (contentType == null)
22: this .contentType = "application/octet-stream";
23: else
24: this .contentType = contentType;
25: this .name = name;
26: }
27:
28: public String getContentType() {
29: return contentType;
30: }
31:
32: public InputStream getInputStream() {
33: // remove the final CR/LF
34: return new ByteArrayInputStream(bytes, 0, bytes.length - 2);
35: }
36:
37: public String getName() {
38: return name;
39: }
40:
41: public OutputStream getOutputStream() throws IOException {
42: throw new FileNotFoundException();
43: }
44: }
|