1 20 package org.apache.maven.cactus.sample.util; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.PrintWriter ; 24 25 import javax.servlet.ServletOutputStream ; 26 import javax.servlet.http.HttpServletResponse ; 27 import javax.servlet.http.HttpServletResponseWrapper ; 28 29 45 public class GenericResponseWrapper extends HttpServletResponseWrapper 46 { 47 50 private ByteArrayOutputStream output; 51 52 58 private int contentLength; 59 60 66 private String contentType; 67 68 70 73 public GenericResponseWrapper(HttpServletResponse theResponse) 74 { 75 super(theResponse); 76 this.output = new ByteArrayOutputStream (); 77 } 78 79 81 84 public byte[] getData() 85 { 86 return output.toByteArray(); 87 } 88 89 91 94 public ServletOutputStream getOutputStream() 95 { 96 return new FilterServletOutputStream(this.output); 97 } 98 99 102 public void setContentLength(int theLength) 103 { 104 this.contentLength = theLength; 105 super.setContentLength(theLength); 106 } 107 108 111 public int getContentLength() 112 { 113 return this.contentLength; 114 } 115 116 119 public void setContentType(String theType) 120 { 121 this.contentType = theType; 122 super.setContentType(theType); 123 } 124 125 128 public String getContentType() 129 { 130 return this.contentType; 131 } 132 133 136 public PrintWriter getWriter() 137 { 138 return new PrintWriter (getOutputStream(), true); 139 } 140 } 141 | Popular Tags |