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  
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   * <a href="GenericServletResponse.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class GenericServletResponse extends HttpServletResponseWrapper {
31  
32      public GenericServletResponse(HttpServletResponse response) {
33          super(response);
34  
35          _ubaos = new UnsyncByteArrayOutputStream();
36      }
37  
38      public byte[] getData() {
39          return _ubaos.toByteArray();
40      }
41  
42      public int getContentLength() {
43          return _contentLength;
44      }
45  
46      public void setContentLength(int length) {
47          super.setContentLength(length);
48  
49          _contentLength = length;
50      }
51  
52      public String getContentType() {
53          return _contentType;
54      }
55  
56      public void setContentType(String type) {
57          super.setContentType(type);
58  
59          _contentType = type;
60      }
61  
62      public ServletOutputStream getOutputStream() {
63          return new GenericServletOutputStream(_ubaos);
64      }
65  
66      public PrintWriter getWriter() {
67          return new PrintWriter(getOutputStream(), true);
68      }
69  
70      private int _contentLength;
71      private String _contentType;
72      private UnsyncByteArrayOutputStream _ubaos;
73  
74  }