1 8 9 package org.enhydra.oyster.activation; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import org.enhydra.oyster.util.ConvertAssist; 13 import javax.activation.DataSource ; 14 import javax.activation.MimetypesFileTypeMap ; 15 import java.io.ByteArrayInputStream ; 16 import java.io.InputStream ; 17 import java.io.OutputStream ; 18 import java.io.IOException ; 19 20 21 28 public class StreamDataSource implements DataSource { 29 30 33 private String contentType = null; 34 35 38 private String fileName = ""; 39 40 43 private byte[] att = null; 44 45 54 public StreamDataSource(InputStream in0, String fileName0) throws SMIMEException { 55 56 att = ConvertAssist.inStreamToByteArray(in0); 57 58 if(fileName0 != null) { 59 contentType = new MimetypesFileTypeMap ().getContentType(fileName0); 60 fileName = new String (fileName0); 61 } 62 if( contentType == null || contentType.equalsIgnoreCase("") ) 63 contentType = "application/octet-stream"; 64 65 contentType = contentType + "; name=\"" + fileName0 + "\""; 66 } 67 68 77 public void setContentType(String contType0) { 78 contentType = contType0; 79 } 80 81 85 public String getContentType () { 86 return contentType; 87 } 88 89 94 public InputStream getInputStream () throws IOException { 95 return new ByteArrayInputStream (att); 96 } 97 98 102 public String getName () { 103 return fileName; 104 } 105 106 112 public OutputStream getOutputStream () throws IOException { 113 throw new IOException ("StreamDataSource does not support getOutputStream()"); 114 } 115 116 117 } | Popular Tags |