1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.aggregator.impl;
1819import java.io.IOException;
20import java.io.PrintWriter;
21import java.io.UnsupportedEncodingException;
2223import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import javax.servlet.ServletOutputStream;
26import javax.servlet.http.HttpServletResponse;
27import org.apache.pluto.util.PrintWriterServletOutputStream;
2829publicclassHttpBufferedResponseextends javax.servlet.http.HttpServletResponseWrapper
30 {
31privateboolean usingWriter;
32privateboolean usingStream;
3334/*** Commons logging */35protectedfinalstatic Log log = LogFactory.getLog(HttpBufferedResponse.class);
3637private ServletOutputStream wrappedStream;
38private PrintWriter writer;
3940publicHttpBufferedResponse(HttpServletResponse servletResponse,
41 PrintWriter writer)
42 {
43super(servletResponse);
44this.writer = writer;
45 }
4647public ServletOutputStream getOutputStream() throws IllegalStateException, IOException
48 {
49if (usingWriter)
50 {
51thrownew IllegalStateException("getOutputStream can't be used after getWriter was invoked");
52 }
5354if (wrappedStream == null)
55 {
56 wrappedStream = new PrintWriterServletOutputStream(writer, getResponse().getCharacterEncoding());
57 }
5859 usingStream = true;
6061return wrappedStream;
62 }
6364public PrintWriter getWriter() throws UnsupportedEncodingException, IllegalStateException, IOException {
6566if (usingStream)
67 {
68thrownew IllegalStateException("getWriter can't be used after getOutputStream was invoked");
69 }
7071 usingWriter = true;
7273return writer;
74 }
757677publicvoid setBufferSize(int size)
78 {
79// ignore80 }
8182publicint getBufferSize()
83 {
84return 0;
85 }
8687publicvoid flushBuffer() throws IOException
88 {
89 writer.flush();
90 }
9192publicboolean isCommitted()
93 {
94return false;
95 }
9697publicvoid reset()
98 {
99// ignore right now100 }
101 }