1 17 package org.apache.axis2.attachments; 18 19 import javax.activation.DataSource ; 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 25 28 public class ByteArrayDataSource implements DataSource { 29 30 private byte[] data; 31 32 private String type; 33 34 public ByteArrayDataSource(byte[] data, String type) { 35 super(); 36 this.data = data; 37 this.type = type; 38 } 39 40 public ByteArrayDataSource(byte[] data) { 41 super(); 42 this.data = data; 43 } 44 45 public void setType(String type) { 46 this.type = type; 47 } 48 49 public String getContentType() { 50 if (type == null) 51 return "application/octet-stream"; 52 else 53 return type; 54 } 55 56 public InputStream getInputStream() throws IOException { 57 return new ByteArrayInputStream (data); 58 } 59 60 public String getName() { 61 62 return "ByteArrayDataSource"; 63 } 64 65 public OutputStream getOutputStream() throws IOException { 66 throw new IOException ("Not Supported"); 67 } 68 } 69 70 | Popular Tags |