View Javadoc

1   /*
2    * Copyright 2004 Jeff Johnston
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.extremecomponents.table.filter;
17  
18  import java.io.ByteArrayOutputStream;
19  import java.io.PrintWriter;
20  
21  import javax.servlet.ServletOutputStream;
22  import javax.servlet.http.HttpServletResponse;
23  import javax.servlet.http.HttpServletResponseWrapper;
24  
25  
26  /***
27   * @author Jeff Johnston
28   */
29  public class GenericResponseWrapper extends HttpServletResponseWrapper
30  {
31  	private ByteArrayOutputStream output;
32  	private int contentLength;
33  	private String contentType;
34  
35  	public GenericResponseWrapper(HttpServletResponse response)
36  	{
37  		super(response);
38  		output = new ByteArrayOutputStream();
39  	}
40  
41  	public byte[] getData()
42  	{
43  		return output.toByteArray();
44  	}
45  
46  	public ServletOutputStream getOutputStream()
47  	{
48  		return new FilterServletOutputStream(output);
49  	}
50  
51  	public PrintWriter getWriter()
52  	{
53  		return new PrintWriter(getOutputStream(), true);
54  	}
55  
56  	public void setContentLength(int length)
57  	{
58  		this.contentLength = length;
59  		super.setContentLength(length);
60  	}
61  
62  	public int getContentLength()
63  	{
64  		return contentLength;
65  	}
66  
67  	public void setContentType(String type)
68  	{
69  		this.contentType = type;
70  		super.setContentType(type);
71  	}
72  
73  	public String getContentType()
74  	{
75  		return contentType;
76  	}
77  }