001
014
015 package com.liferay.util.servlet;
016
017 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
018 import com.liferay.portal.kernel.io.unsync.UnsyncPrintWriter;
019
020 import java.io.PrintWriter;
021
022 import javax.servlet.ServletOutputStream;
023 import javax.servlet.http.HttpServletResponse;
024 import javax.servlet.http.HttpServletResponseWrapper;
025
026
029 public class GenericServletResponse extends HttpServletResponseWrapper {
030
031 public GenericServletResponse(HttpServletResponse response) {
032 super(response);
033
034 _ubaos = new UnsyncByteArrayOutputStream();
035 }
036
037 public byte[] getData() {
038 return _ubaos.toByteArray();
039 }
040
041 public int getContentLength() {
042 return _contentLength;
043 }
044
045 public void setContentLength(int length) {
046 super.setContentLength(length);
047
048 _contentLength = length;
049 }
050
051 public String getContentType() {
052 return _contentType;
053 }
054
055 public void setContentType(String type) {
056 super.setContentType(type);
057
058 _contentType = type;
059 }
060
061 public ServletOutputStream getOutputStream() {
062 return new GenericServletOutputStream(_ubaos);
063 }
064
065 public PrintWriter getWriter() {
066 return new UnsyncPrintWriter(getOutputStream(), true);
067 }
068
069 private int _contentLength;
070 private String _contentType;
071 private UnsyncByteArrayOutputStream _ubaos;
072
073 }