1 64 65 70 package com.jcorporate.expresso.core.misc; 71 72 import javax.activation.DataSource ; 73 import java.io.ByteArrayInputStream ; 74 import java.io.IOException ; 75 import java.io.InputStream ; 76 import java.io.OutputStream ; 77 import java.io.UnsupportedEncodingException ; 78 79 87 public class ByteArrayDataSource implements DataSource { 88 private byte[] data; private String type; private String name = "attachment_file"; 91 92 99 public ByteArrayDataSource(byte data[], String type, String name) { 100 this.data = data; 101 this.type = type; 102 this.name = name; 103 } 104 105 112 public ByteArrayDataSource(String text, String type, String name) { 113 try { 114 this.data = text.getBytes("UTF-8"); 115 } catch (UnsupportedEncodingException uex) { 116 } 117 this.type = type; 118 this.name = name; 119 } 120 121 123 128 public InputStream getInputStream() throws IOException { 129 if (data == null) { 130 throw new IOException ("no data"); 131 } 132 return new ByteArrayInputStream (data); 133 } 134 135 140 public OutputStream getOutputStream() throws IOException { 141 throw new IOException ("cannot do this"); 142 } 143 144 149 public String getContentType() { 150 return type; 151 } 152 153 158 public String getName() { 159 return name; 160 } 161 } 162 | Popular Tags |