01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id: ByteArrayDataSource.java 3506 2006-12-08 04:11:53Z zjin $
23: */
24: package com.bostechcorp.cbesb.runtime.ccsl.nmhandler;
25:
26: import java.io.ByteArrayInputStream;
27: import java.io.IOException;
28: import java.io.InputStream;
29: import java.io.OutputStream;
30:
31: import javax.activation.DataSource;
32:
33: /**
34: * A helper class which provides a {@link DataSource} from a byte[]
35: * which can be read as many times as required.
36: */
37: public class ByteArrayDataSource implements DataSource {
38:
39: private byte[] data;
40: private String contentType;
41: private String name = "unused";
42:
43: public ByteArrayDataSource(byte[] data) {
44: this (data, null, null);
45: }
46:
47: public ByteArrayDataSource(byte[] data, String contentType) {
48: this (data, contentType, null);
49: }
50:
51: public ByteArrayDataSource(byte[] data, String contentType,
52: String name) {
53: this .data = data;
54: this .contentType = contentType;
55: this .name = name;
56: }
57:
58: public String getContentType() {
59: return contentType;
60: }
61:
62: public InputStream getInputStream() throws IOException {
63: if (data == null) {
64: throw new IOException("no data.");
65: }
66: return new ByteArrayInputStream(data);
67: }
68:
69: public String getName() {
70: return name;
71: }
72:
73: public OutputStream getOutputStream() throws IOException {
74: throw new IOException("getOutputStream() not supported.");
75: }
76:
77: public byte[] getData() {
78: return data;
79: }
80: }
|