GenericResponseWrapper.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package org.activiti;
  2. import javax.servlet.ServletOutputStream;
  3. import javax.servlet.http.HttpServletResponse;
  4. import javax.servlet.http.HttpServletResponseWrapper;
  5. import java.io.ByteArrayOutputStream;
  6. import java.io.PrintWriter;
  7. public class GenericResponseWrapper extends HttpServletResponseWrapper {
  8. private ByteArrayOutputStream output;
  9. private int contentLength;
  10. private String contentType;
  11. public GenericResponseWrapper(HttpServletResponse response) {
  12. super(response);
  13. output = new ByteArrayOutputStream();
  14. }
  15. public byte[] getData() {
  16. return output.toByteArray();
  17. }
  18. public ServletOutputStream getOutputStream() {
  19. return new FilterServletOutputStream(output);
  20. }
  21. public PrintWriter getWriter() {
  22. return new PrintWriter(getOutputStream(), true);
  23. }
  24. public void setContentLength(int length) {
  25. this.contentLength = length;
  26. super.setContentLength(length);
  27. }
  28. public int getContentLength() {
  29. return contentLength;
  30. }
  31. public void setContentType(String type) {
  32. this.contentType = type;
  33. super.setContentType(type);
  34. }
  35. public String getContentType() {
  36. return contentType;
  37. }
  38. }