1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.aggregator.impl; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.io.PrintWriter; |
21 |
|
import java.io.UnsupportedEncodingException; |
22 |
|
|
23 |
|
import org.apache.commons.logging.Log; |
24 |
|
import org.apache.commons.logging.LogFactory; |
25 |
|
import javax.servlet.ServletOutputStream; |
26 |
|
import javax.servlet.http.HttpServletResponse; |
27 |
|
import org.apache.pluto.util.PrintWriterServletOutputStream; |
28 |
|
|
29 |
|
public class HttpBufferedResponse extends javax.servlet.http.HttpServletResponseWrapper |
30 |
|
{ |
31 |
|
private boolean usingWriter; |
32 |
|
private boolean usingStream; |
33 |
|
|
34 |
|
|
35 |
0 |
protected final static Log log = LogFactory.getLog(HttpBufferedResponse.class); |
36 |
|
|
37 |
|
private ServletOutputStream wrappedStream; |
38 |
|
private PrintWriter writer; |
39 |
|
|
40 |
|
public HttpBufferedResponse(HttpServletResponse servletResponse, |
41 |
|
PrintWriter writer) |
42 |
|
{ |
43 |
0 |
super(servletResponse); |
44 |
0 |
this.writer = writer; |
45 |
0 |
} |
46 |
|
|
47 |
|
public ServletOutputStream getOutputStream() throws IllegalStateException, IOException |
48 |
|
{ |
49 |
0 |
if (usingWriter) |
50 |
|
{ |
51 |
0 |
throw new IllegalStateException("getOutputStream can't be used after getWriter was invoked"); |
52 |
|
} |
53 |
|
|
54 |
0 |
if (wrappedStream == null) |
55 |
|
{ |
56 |
0 |
wrappedStream = new PrintWriterServletOutputStream(writer, getResponse().getCharacterEncoding()); |
57 |
|
} |
58 |
|
|
59 |
0 |
usingStream = true; |
60 |
|
|
61 |
0 |
return wrappedStream; |
62 |
|
} |
63 |
|
|
64 |
|
public PrintWriter getWriter() throws UnsupportedEncodingException, IllegalStateException, IOException { |
65 |
|
|
66 |
0 |
if (usingStream) |
67 |
|
{ |
68 |
0 |
throw new IllegalStateException("getWriter can't be used after getOutputStream was invoked"); |
69 |
|
} |
70 |
|
|
71 |
0 |
usingWriter = true; |
72 |
|
|
73 |
0 |
return writer; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
public void setBufferSize(int size) |
78 |
|
{ |
79 |
|
|
80 |
0 |
} |
81 |
|
|
82 |
|
public int getBufferSize() |
83 |
|
{ |
84 |
0 |
return 0; |
85 |
|
} |
86 |
|
|
87 |
|
public void flushBuffer() throws IOException |
88 |
|
{ |
89 |
0 |
writer.flush(); |
90 |
0 |
} |
91 |
|
|
92 |
|
public boolean isCommitted() |
93 |
|
{ |
94 |
0 |
return false; |
95 |
|
} |
96 |
|
|
97 |
|
public void reset() |
98 |
|
{ |
99 |
|
|
100 |
0 |
} |
101 |
|
} |