1 8 package org.jboss.axis.attachments; 9 10 import javax.activation.DataSource ; 11 import javax.mail.internet.MimeMultipart ; 12 import java.io.ByteArrayInputStream ; 13 import java.io.ByteArrayOutputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.OutputStream ; 17 18 public class MimeMultipartDataSource implements DataSource 19 { 20 public static final String CONTENT_TYPE = "multipart/mixed"; 21 22 private final String name; 23 private final String contentType; 24 private byte[] data; 25 private ByteArrayInputStream is; 26 private ByteArrayOutputStream os; 27 28 public MimeMultipartDataSource(String name, MimeMultipart data) 29 { 30 this.name = name; 31 this.contentType = data == null ? CONTENT_TYPE : data.getContentType(); 32 os = new ByteArrayOutputStream (); 33 try 34 { 35 if (data != null) 36 { 37 data.writeTo(os); 38 } 39 } 40 catch (Exception e) 41 { 42 } 44 } 46 public String getName() 47 { 48 return name; 49 } 51 public String getContentType() 52 { 53 return contentType; 54 } 56 public InputStream getInputStream() throws IOException 57 { 58 if (os.size() != 0) 59 { 60 data = os.toByteArray(); 61 os.reset(); 62 } 63 return new ByteArrayInputStream (data == null ? new byte[0] : data); 64 } 66 public OutputStream getOutputStream() throws IOException 67 { 68 if (os.size() != 0) 69 { 70 data = os.toByteArray(); 71 os.reset(); 72 } 73 return os; 74 } } | Popular Tags |