1
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
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 }