1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.http; |
12 | |
|
13 | |
import java.io.BufferedWriter; |
14 | |
import java.io.FilterWriter; |
15 | |
import java.io.IOException; |
16 | |
import java.io.OutputStream; |
17 | |
import java.io.OutputStreamWriter; |
18 | |
import java.io.UnsupportedEncodingException; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class ResponseWriter extends FilterWriter |
24 | |
{ |
25 | |
public static final String CRLF = "\r\n"; |
26 | |
public static final String ISO_8859_1 = "ISO-8859-1"; |
27 | 0 | private OutputStream outStream = null; |
28 | 0 | private String encoding = null; |
29 | |
|
30 | |
public ResponseWriter(final OutputStream outStream) throws UnsupportedEncodingException |
31 | |
{ |
32 | 0 | this(outStream, CRLF, ISO_8859_1); |
33 | 0 | } |
34 | |
|
35 | |
public ResponseWriter(final OutputStream outStream, final String encoding) |
36 | |
throws UnsupportedEncodingException |
37 | |
{ |
38 | 0 | this(outStream, CRLF, encoding); |
39 | 0 | } |
40 | |
|
41 | |
public ResponseWriter(final OutputStream outStream, final String lineSeparator, final String encoding) |
42 | |
throws UnsupportedEncodingException |
43 | |
{ |
44 | 0 | super(new BufferedWriter(new OutputStreamWriter(outStream, encoding))); |
45 | 0 | this.outStream = outStream; |
46 | 0 | this.encoding = encoding; |
47 | 0 | } |
48 | |
|
49 | |
public String getEncoding() |
50 | |
{ |
51 | 0 | return encoding; |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public void close() throws IOException |
56 | |
{ |
57 | 0 | if (outStream != null) |
58 | |
{ |
59 | 0 | super.close(); |
60 | 0 | outStream = null; |
61 | |
} |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
public void flush() throws IOException |
66 | |
{ |
67 | 0 | if (outStream != null) |
68 | |
{ |
69 | 0 | super.flush(); |
70 | 0 | outStream.flush(); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
public void write(byte b) throws IOException |
75 | |
{ |
76 | 0 | super.flush(); |
77 | 0 | outStream.write(b); |
78 | 0 | } |
79 | |
|
80 | |
public void write(byte[] b) throws IOException |
81 | |
{ |
82 | 0 | super.flush(); |
83 | 0 | outStream.write(b); |
84 | 0 | } |
85 | |
|
86 | |
public void write(byte[] b, int off, int len) throws IOException |
87 | |
{ |
88 | 0 | super.flush(); |
89 | 0 | outStream.write(b, off, len); |
90 | 0 | } |
91 | |
|
92 | |
public void print(String s) throws IOException |
93 | |
{ |
94 | 0 | if (s == null) |
95 | |
{ |
96 | 0 | s = "null"; |
97 | |
} |
98 | 0 | write(s); |
99 | 0 | } |
100 | |
|
101 | |
public void print(int i) throws IOException |
102 | |
{ |
103 | 0 | write(Integer.toString(i)); |
104 | 0 | } |
105 | |
|
106 | |
public void println(int i) throws IOException |
107 | |
{ |
108 | 0 | write(Integer.toString(i)); |
109 | 0 | write(CRLF); |
110 | 0 | } |
111 | |
|
112 | |
public void println(String s) throws IOException |
113 | |
{ |
114 | 0 | print(s); |
115 | 0 | write(CRLF); |
116 | 0 | } |
117 | |
|
118 | |
public void println() throws IOException |
119 | |
{ |
120 | 0 | write(CRLF); |
121 | 0 | } |
122 | |
|
123 | |
} |