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 OctetStreamDataSource implements DataSource 18 { 19 public static final String CONTENT_TYPE = "application/octetstream"; 20 21 private final String name; 22 private byte[] data; 23 private ByteArrayOutputStream os; 24 25 public OctetStreamDataSource(String name, OctetStream data) 26 { 27 this.name = name; 28 this.data = data == null ? null : data.getBytes(); 29 os = new ByteArrayOutputStream (); 30 } 32 public String getName() 33 { 34 return name; 35 } 37 public String getContentType() 38 { 39 return CONTENT_TYPE; 40 } 42 public InputStream getInputStream() throws IOException 43 { 44 if (os.size() != 0) 45 { 46 data = os.toByteArray(); 47 } 48 return new ByteArrayInputStream (data == null ? new byte[0] : data); 49 } 51 public OutputStream getOutputStream() throws IOException 52 { 53 if (os.size() != 0) 54 { 55 data = os.toByteArray(); 56 } 57 return new ByteArrayOutputStream (); 58 } } | Popular Tags |