1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl; |
12 | |
|
13 | |
import java.io.BufferedOutputStream; |
14 | |
import java.io.IOException; |
15 | |
import java.io.OutputStream; |
16 | |
import java.net.Socket; |
17 | |
|
18 | |
import org.apache.commons.io.output.ByteArrayOutputStream; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class ResponseOutputStream extends BufferedOutputStream |
28 | |
{ |
29 | 0 | private static ByteArrayOutputStream defaultStream = new ByteArrayOutputStream(); |
30 | |
|
31 | 0 | private boolean used = false; |
32 | 0 | private boolean isDefault = false; |
33 | 0 | private Socket socket = null; |
34 | |
|
35 | |
public ResponseOutputStream() |
36 | |
{ |
37 | 0 | super(defaultStream); |
38 | 0 | isDefault = true; |
39 | 0 | } |
40 | |
|
41 | |
public ResponseOutputStream(OutputStream stream) |
42 | |
{ |
43 | 0 | super(stream); |
44 | 0 | } |
45 | |
|
46 | |
public ResponseOutputStream(Socket socket) throws IOException |
47 | |
{ |
48 | 0 | super(socket.getOutputStream()); |
49 | 0 | this.socket = socket; |
50 | 0 | } |
51 | |
|
52 | |
public void write(int b) throws IOException |
53 | |
{ |
54 | 0 | super.write(b); |
55 | 0 | used = true; |
56 | 0 | } |
57 | |
|
58 | |
public byte[] getBytes() throws IOException |
59 | |
{ |
60 | 0 | if (isDefault) |
61 | |
{ |
62 | 0 | flush(); |
63 | 0 | return defaultStream.toByteArray(); |
64 | |
} |
65 | 0 | return null; |
66 | |
} |
67 | |
|
68 | |
public boolean isUsed() |
69 | |
{ |
70 | 0 | return used; |
71 | |
} |
72 | |
|
73 | |
public Socket getSocket() |
74 | |
{ |
75 | 0 | return socket; |
76 | |
} |
77 | |
} |