001
014
015 package com.liferay.util.servlet;
016
017 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
018 import com.liferay.portal.kernel.util.UnsyncPrintWriterPool;
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 int getContentLength() {
038 return _contentLength;
039 }
040
041 @Override
042 public String getContentType() {
043 return _contentType;
044 }
045
046 public byte[] getData() {
047 return _ubaos.toByteArray();
048 }
049
050 @Override
051 public ServletOutputStream getOutputStream() {
052 return new GenericServletOutputStream(_ubaos);
053 }
054
055 @Override
056 public PrintWriter getWriter() {
057 return UnsyncPrintWriterPool.borrow(getOutputStream());
058 }
059
060 @Override
061 public void setContentLength(int length) {
062 super.setContentLength(length);
063
064 _contentLength = length;
065 }
066
067 @Override
068 public void setContentType(String type) {
069 super.setContentType(type);
070
071 _contentType = type;
072 }
073
074 private int _contentLength;
075 private String _contentType;
076 private UnsyncByteArrayOutputStream _ubaos;
077
078 }