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