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