1 12 13 package com.openedit.modules.email; 14 15 16 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.IOException ; 48 import java.io.InputStream ; 49 import java.io.OutputStream ; 50 import java.io.UnsupportedEncodingException ; 51 52 import javax.activation.DataSource ; 53 54 55 63 public class ByteArrayDataSource implements DataSource  64 { 65 private String type; private byte[] data; 68 69 public ByteArrayDataSource(InputStream is, String type) 70 { 71 this.type = type; 72 73 try 74 { 75 ByteArrayOutputStream os = new ByteArrayOutputStream (); 76 int ch; 77 78 while ((ch = is.read()) != -1) 79 80 os.write(ch); 83 84 data = os.toByteArray(); 85 } 86 catch (IOException ioex) 87 { 88 } 89 } 90 91 92 public ByteArrayDataSource(byte[] data, String type) 93 { 94 this.data = data; 95 this.type = type; 96 } 97 98 99 public ByteArrayDataSource(String data, String type) 100 { 101 try 102 { 103 this.data = data.getBytes("iso-8859-1"); 107 } 108 catch (UnsupportedEncodingException uex) 109 { 110 } 111 112 this.type = type; 113 } 114 115 120 public String getContentType() 121 { 122 return type; 123 } 124 125 132 public InputStream getInputStream() throws IOException  133 { 134 if (data == null) 135 { 136 throw new IOException ("no data"); 137 } 138 139 return new ByteArrayInputStream (data); 140 } 141 142 147 public String getName() 148 { 149 return "dummy"; 150 } 151 152 159 public OutputStream getOutputStream() throws IOException  160 { 161 throw new IOException ("cannot do this"); 162 } 163 } 164 | Popular Tags |