1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.streaming;
12
13 import org.mule.impl.ThreadSafeAccess;
14 import org.mule.providers.AbstractMessageAdapter;
15 import org.mule.providers.NullPayload;
16 import org.mule.umo.UMOEvent;
17 import org.mule.umo.provider.OutputHandler;
18 import org.mule.umo.provider.UMOStreamMessageAdapter;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23
24
25
26
27
28
29
30 public class StreamMessageAdapter extends AbstractMessageAdapter implements UMOStreamMessageAdapter
31 {
32
33
34
35 private static final long serialVersionUID = 6794965828515586752L;
36
37 protected InputStream in;
38 protected OutputStream out;
39 protected OutputHandler handler;
40 private static NullPayload NULL_PAYLOAD = NullPayload.getInstance();
41
42 public StreamMessageAdapter(InputStream in)
43 {
44 this.in = in;
45 }
46
47 public StreamMessageAdapter(InputStream in, OutputStream out)
48 {
49 this.in = in;
50 this.out = out;
51 }
52
53 public StreamMessageAdapter(OutputHandler handler)
54 {
55 this.handler = handler;
56 }
57
58 public StreamMessageAdapter(OutputStream out, OutputHandler handler)
59 {
60 this.out = out;
61 this.handler = handler;
62 }
63
64 public StreamMessageAdapter(InputStream in, OutputStream out, OutputHandler handler)
65 {
66 this.in = in;
67 this.out = out;
68 this.handler = handler;
69 }
70
71 protected StreamMessageAdapter(StreamMessageAdapter template)
72 {
73 super(template);
74 in = template.in;
75 out = template.out;
76 handler = template.handler;
77 }
78
79
80
81
82
83
84
85
86
87 public String getPayloadAsString(String encoding) throws Exception
88 {
89 throw new UnsupportedOperationException("getPayloadAsString");
90 }
91
92
93
94
95
96
97
98 public byte[] getPayloadAsBytes() throws Exception
99 {
100 throw new UnsupportedOperationException("getPayloadAsBytes");
101 }
102
103
104
105
106
107
108
109
110
111 public Object getPayload()
112 {
113 if (in != null)
114 {
115 return in;
116 }
117 return NULL_PAYLOAD;
118 }
119
120 public InputStream getInputStream()
121 {
122 return in;
123 }
124
125 public OutputStream getOutputStream()
126 {
127 return out;
128 }
129
130 public void write(UMOEvent event) throws IOException
131 {
132 handler.write(event, out);
133 }
134
135 public OutputHandler getOutputHandler()
136 {
137 return handler;
138 }
139
140 public void setOutputHandler(OutputHandler handler)
141 {
142 this.handler = handler;
143 }
144
145
146
147
148
149
150 public void release()
151 {
152
153 }
154
155 public ThreadSafeAccess newThreadCopy()
156 {
157 return new StreamMessageAdapter(this);
158 }
159
160 }