1 8 package org.jboss.axis.attachments; 9 10 import javax.activation.DataSource ; 11 import java.io.ByteArrayInputStream ; 12 import java.io.ByteArrayOutputStream ; 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.io.OutputStream ; 16 17 public class PlainTextDataSource implements DataSource 18 { 19 public static final String CONTENT_TYPE = "text/plain"; 20 21 private final String name; 22 private byte[] data; 23 private ByteArrayInputStream is; 24 private ByteArrayOutputStream os; 25 26 public PlainTextDataSource(String name, String data) 27 { 28 this.name = name; 29 this.data = data == null ? null : data.getBytes(); 30 os = new ByteArrayOutputStream (); 31 } 33 public String getName() 34 { 35 return name; 36 } 38 public String getContentType() 39 { 40 return CONTENT_TYPE; 41 } 43 public InputStream getInputStream() throws IOException 44 { 45 if (os.size() != 0) 46 { 47 data = os.toByteArray(); 48 } 49 return new ByteArrayInputStream (data == null ? new byte[0] : data); 50 } 52 public OutputStream getOutputStream() throws IOException 53 { 54 if (os.size() != 0) 55 { 56 data = os.toByteArray(); 57 } 58 return new ByteArrayOutputStream (); 59 } } | Popular Tags |