1 56 package org.opencrx.mail.workflow; 57 58 import java.io.ByteArrayInputStream ; 59 import java.io.ByteArrayOutputStream ; 60 import java.io.IOException ; 61 import java.io.InputStream ; 62 import java.io.OutputStream ; 63 import java.io.UnsupportedEncodingException ; 64 65 import javax.activation.DataSource ; 66 67 public class ByteArrayDataSource implements DataSource { 68 private byte[] data; private String type; 71 72 public ByteArrayDataSource(InputStream is, String type) { 73 this.type = type; 74 try { 75 ByteArrayOutputStream os = new ByteArrayOutputStream (); 76 int ch; 77 78 while ((ch = is.read()) != -1) 79 os.write(ch); 82 data = os.toByteArray(); 83 84 } catch (IOException ioex) { } 85 } 86 87 88 public ByteArrayDataSource(byte[] data, String type) { 89 this.data = data; 90 this.type = type; 91 } 92 93 94 public ByteArrayDataSource(String data, String type) { 95 try { 96 this.data = data.getBytes("iso-8859-1"); 100 } catch (UnsupportedEncodingException uex) { } 101 this.type = type; 102 } 103 104 108 public InputStream getInputStream() throws IOException { 109 if (data == null) 110 throw new IOException ("no data"); 111 return new ByteArrayInputStream (data); 112 } 113 114 public OutputStream getOutputStream() throws IOException { 115 throw new IOException ("cannot do this"); 116 } 117 118 public String getContentType() { 119 return type; 120 } 121 122 public String getName() { 123 return "dummy"; 124 } 125 } 126 | Popular Tags |