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: StringDataSource.java 9243 2007-09-25 00:49:54Z lzheng $
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 String
35: * which can be read as many times as required.
36: */
37: public class StringDataSource implements DataSource {
38:
39: private String data;
40: private String contentType;
41: private String name = "unused";
42:
43: public StringDataSource(String data) {
44: this (data, null, null);
45: }
46:
47: public StringDataSource(String data, String contentType) {
48: this (data, contentType, null);
49: }
50:
51: public StringDataSource(String data, String contentType, String name) {
52: this .data = data;
53: this .contentType = contentType;
54: this .name = name;
55: }
56:
57: public String getContentType() {
58: return contentType;
59: }
60:
61: public InputStream getInputStream() throws IOException {
62: if (data == null) {
63: throw new IOException("no data.");
64: }
65: return new ByteArrayInputStream(data.getBytes("utf-8"));
66: }
67:
68: public String getName() {
69: return name;
70: }
71:
72: public OutputStream getOutputStream() throws IOException {
73: throw new IOException("getOutputStream() not supported.");
74: }
75:
76: public String getData() {
77: return data;
78: }
79: }
|