1 package com.knowgate.dfs; 2 3 40 41 import java.io.*; 42 import javax.activation.*; 43 44 55 public class ByteArrayDataSource implements DataSource { 56 private byte[] data; private String type; 59 60 public ByteArrayDataSource(InputStream is, String type) { 61 this.type = type; 62 try { 63 ByteArrayOutputStream os = new ByteArrayOutputStream(); 64 int ch; 65 66 while ((ch = is.read()) != -1) 67 os.write(ch); 70 data = os.toByteArray(); 71 72 } catch (IOException ioex) { } 73 } 74 75 76 public ByteArrayDataSource(byte[] data, String type) { 77 this.data = data; 78 this.type = type; 79 } 80 81 82 public ByteArrayDataSource(String data, String type) { 83 try { 84 this.data = data.getBytes("iso-8859-1"); 88 } catch (UnsupportedEncodingException uex) { } 89 this.type = type; 90 } 91 92 96 public InputStream getInputStream() throws IOException { 97 if (data == null) 98 throw new IOException("no data"); 99 return new ByteArrayInputStream(data); 100 } 101 102 public OutputStream getOutputStream() throws IOException { 103 throw new IOException("cannot do this"); 104 } 105 106 public String getContentType() { 107 return type; 108 } 109 110 public String getName() { 111 return "dummy"; 112 } 113 } 114 | Popular Tags |