1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.servlet;
16  
17  import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
18  import com.liferay.portal.kernel.io.unsync.UnsyncPrintWriter;
19  
20  import java.io.PrintWriter;
21  
22  import javax.servlet.ServletOutputStream;
23  import javax.servlet.http.HttpServletResponse;
24  import javax.servlet.http.HttpServletResponseWrapper;
25  
26  /**
27   * <a href="GenericServletResponse.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class GenericServletResponse extends HttpServletResponseWrapper {
32  
33      public GenericServletResponse(HttpServletResponse response) {
34          super(response);
35  
36          _ubaos = new UnsyncByteArrayOutputStream();
37      }
38  
39      public byte[] getData() {
40          return _ubaos.toByteArray();
41      }
42  
43      public int getContentLength() {
44          return _contentLength;
45      }
46  
47      public void setContentLength(int length) {
48          super.setContentLength(length);
49  
50          _contentLength = length;
51      }
52  
53      public String getContentType() {
54          return _contentType;
55      }
56  
57      public void setContentType(String type) {
58          super.setContentType(type);
59  
60          _contentType = type;
61      }
62  
63      public ServletOutputStream getOutputStream() {
64          return new GenericServletOutputStream(_ubaos);
65      }
66  
67      public PrintWriter getWriter() {
68          return new UnsyncPrintWriter(getOutputStream(), true);
69      }
70  
71      private int _contentLength;
72      private String _contentType;
73      private UnsyncByteArrayOutputStream _ubaos;
74  
75  }