1 16 package org.apache.axis.attachments; 17 18 import javax.activation.DataSource ; 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 25 public class OctetStreamDataSource implements DataSource { 26 public static final String CONTENT_TYPE = "application/octet-stream"; 27 28 private final String name; 29 private byte[] data; 30 private ByteArrayOutputStream os; 31 32 public OctetStreamDataSource(String name, OctetStream data) { 33 this.name = name; 34 this.data = data == null ? null : data.getBytes(); 35 os = new ByteArrayOutputStream (); 36 } 38 public String getName() { 39 return name; 40 } 42 public String getContentType() { 43 return CONTENT_TYPE; 44 } 46 public InputStream getInputStream() throws IOException { 47 if (os.size() != 0) { 48 data = os.toByteArray(); 49 } 50 return new ByteArrayInputStream (data == null ? new byte[0] : data); 51 } 53 public OutputStream getOutputStream() throws IOException { 54 if (os.size() != 0) { 55 data = os.toByteArray(); 56 } 57 return new ByteArrayOutputStream (); 58 } } | Popular Tags |