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 | 0 | private static NullPayload NULL_PAYLOAD = NullPayload.getInstance(); |
41 | |
|
42 | |
public StreamMessageAdapter(InputStream in) |
43 | 0 | { |
44 | 0 | this.in = in; |
45 | 0 | } |
46 | |
|
47 | |
public StreamMessageAdapter(InputStream in, OutputStream out) |
48 | 0 | { |
49 | 0 | this.in = in; |
50 | 0 | this.out = out; |
51 | 0 | } |
52 | |
|
53 | |
public StreamMessageAdapter(OutputHandler handler) |
54 | 0 | { |
55 | 0 | this.handler = handler; |
56 | 0 | } |
57 | |
|
58 | |
public StreamMessageAdapter(OutputStream out, OutputHandler handler) |
59 | 0 | { |
60 | 0 | this.out = out; |
61 | 0 | this.handler = handler; |
62 | 0 | } |
63 | |
|
64 | |
public StreamMessageAdapter(InputStream in, OutputStream out, OutputHandler handler) |
65 | 0 | { |
66 | 0 | this.in = in; |
67 | 0 | this.out = out; |
68 | 0 | this.handler = handler; |
69 | 0 | } |
70 | |
|
71 | |
protected StreamMessageAdapter(StreamMessageAdapter template) |
72 | |
{ |
73 | 0 | super(template); |
74 | 0 | in = template.in; |
75 | 0 | out = template.out; |
76 | 0 | handler = template.handler; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public String getPayloadAsString(String encoding) throws Exception |
88 | |
{ |
89 | 0 | throw new UnsupportedOperationException("getPayloadAsString"); |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public byte[] getPayloadAsBytes() throws Exception |
99 | |
{ |
100 | 0 | throw new UnsupportedOperationException("getPayloadAsBytes"); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public Object getPayload() |
112 | |
{ |
113 | 0 | if (in != null) |
114 | |
{ |
115 | 0 | return in; |
116 | |
} |
117 | 0 | return NULL_PAYLOAD; |
118 | |
} |
119 | |
|
120 | |
public InputStream getInputStream() |
121 | |
{ |
122 | 0 | return in; |
123 | |
} |
124 | |
|
125 | |
public OutputStream getOutputStream() |
126 | |
{ |
127 | 0 | return out; |
128 | |
} |
129 | |
|
130 | |
public void write(UMOEvent event) throws IOException |
131 | |
{ |
132 | 0 | handler.write(event, out); |
133 | 0 | } |
134 | |
|
135 | |
public OutputHandler getOutputHandler() |
136 | |
{ |
137 | 0 | return handler; |
138 | |
} |
139 | |
|
140 | |
public void setOutputHandler(OutputHandler handler) |
141 | |
{ |
142 | 0 | this.handler = handler; |
143 | 0 | } |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public void release() |
151 | |
{ |
152 | |
|
153 | 0 | } |
154 | |
|
155 | |
public ThreadSafeAccess newThreadCopy() |
156 | |
{ |
157 | 0 | return new StreamMessageAdapter(this); |
158 | |
} |
159 | |
|
160 | |
} |