| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |   | 
  | 17 |  |  package org.kuali.rice.kew.util; | 
  | 18 |  |   | 
  | 19 |  |  import java.io.BufferedOutputStream; | 
  | 20 |  |  import java.io.ByteArrayInputStream; | 
  | 21 |  |  import java.io.ByteArrayOutputStream; | 
  | 22 |  |  import java.io.IOException; | 
  | 23 |  |  import java.io.InputStream; | 
  | 24 |  |  import java.io.OutputStream; | 
  | 25 |  |  import java.io.UnsupportedEncodingException; | 
  | 26 |  |   | 
  | 27 |  |  import javax.activation.DataSource; | 
  | 28 |  |   | 
  | 29 |  |  import org.kuali.rice.kew.exception.WorkflowRuntimeException; | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 |  |  public class ByteArrayDataSource implements DataSource { | 
  | 37 |  |   | 
  | 38 |  |          private byte[] data;  | 
  | 39 |  |      private String type;  | 
  | 40 |  |   | 
  | 41 |  |       | 
  | 42 | 0 |      public ByteArrayDataSource(InputStream is, String type) { | 
  | 43 | 0 |          this.type = type; | 
  | 44 |  |          try { | 
  | 45 | 0 |              ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 
  | 46 | 0 |              OutputStream os = new BufferedOutputStream(baos); | 
  | 47 |  |              int byteData; | 
  | 48 | 0 |              while ((byteData = is.read()) != -1) { | 
  | 49 | 0 |                  os.write(byteData); | 
  | 50 |  |              } | 
  | 51 | 0 |              os.flush(); | 
  | 52 | 0 |              data = baos.toByteArray(); | 
  | 53 | 0 |          } catch (IOException ioex) { | 
  | 54 | 0 |                  throw new WorkflowRuntimeException(ioex); | 
  | 55 | 0 |          } | 
  | 56 | 0 |      } | 
  | 57 |  |   | 
  | 58 |  |       | 
  | 59 | 0 |      public ByteArrayDataSource(byte[] data, String type) { | 
  | 60 | 0 |          this.data = data; | 
  | 61 | 0 |          this.type = type; | 
  | 62 | 0 |      } | 
  | 63 |  |   | 
  | 64 |  |       | 
  | 65 | 0 |      public ByteArrayDataSource(String data, String type) { | 
  | 66 |  |          try { | 
  | 67 |  |               | 
  | 68 |  |               | 
  | 69 |  |               | 
  | 70 | 0 |              this.data = data.getBytes("iso-8859-1"); | 
  | 71 | 0 |          } catch (UnsupportedEncodingException uex) {} | 
  | 72 | 0 |          this.type = type; | 
  | 73 | 0 |      } | 
  | 74 |  |   | 
  | 75 |  |       | 
  | 76 |  |   | 
  | 77 |  |   | 
  | 78 |  |   | 
  | 79 |  |      public InputStream getInputStream() throws IOException { | 
  | 80 | 0 |          if (data == null) | 
  | 81 | 0 |              throw new IOException("no data"); | 
  | 82 | 0 |          return new ByteArrayInputStream(data); | 
  | 83 |  |      } | 
  | 84 |  |   | 
  | 85 |  |      public OutputStream getOutputStream() throws IOException { | 
  | 86 | 0 |          throw new IOException("cannot do this"); | 
  | 87 |  |      } | 
  | 88 |  |   | 
  | 89 |  |      public String getContentType() { | 
  | 90 | 0 |          return type; | 
  | 91 |  |      } | 
  | 92 |  |   | 
  | 93 |  |      public String getName() { | 
  | 94 | 0 |          return "dummy"; | 
  | 95 |  |      } | 
  | 96 |  |  } |