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 /*** Commons logging */
35 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 super(servletResponse);
44 this.writer = writer;
45 }
46
47 public ServletOutputStream getOutputStream() throws IllegalStateException, IOException
48 {
49 if (usingWriter)
50 {
51 throw new IllegalStateException("getOutputStream can't be used after getWriter was invoked");
52 }
53
54 if (wrappedStream == null)
55 {
56 wrappedStream = new PrintWriterServletOutputStream(writer, getResponse().getCharacterEncoding());
57 }
58
59 usingStream = true;
60
61 return wrappedStream;
62 }
63
64 public PrintWriter getWriter() throws UnsupportedEncodingException, IllegalStateException, IOException {
65
66 if (usingStream)
67 {
68 throw new IllegalStateException("getWriter can't be used after getOutputStream was invoked");
69 }
70
71 usingWriter = true;
72
73 return writer;
74 }
75
76
77 public void setBufferSize(int size)
78 {
79
80 }
81
82 public int getBufferSize()
83 {
84 return 0;
85 }
86
87 public void flushBuffer() throws IOException
88 {
89 writer.flush();
90 }
91
92 public boolean isCommitted()
93 {
94 return false;
95 }
96
97 public void reset()
98 {
99
100 }
101 }