1 25 26 package net.killingar.servlet.filter; 27 28 29 import javax.servlet.ServletOutputStream ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpServletResponseWrapper ; 32 import java.io.ByteArrayOutputStream ; 33 import java.io.PrintWriter ; 34 35 36 public class GenericResponseWrapper extends HttpServletResponseWrapper 37 { 38 private ByteArrayOutputStream output; 39 private int contentLength; 40 private String contentType; 41 42 43 44 45 46 47 48 49 public byte[] getData() 50 { 51 return output.toByteArray(); 52 } 53 54 55 public GenericResponseWrapper(HttpServletResponse response) 56 { 57 super(response); 58 output = new ByteArrayOutputStream (); 59 } 60 61 62 public ServletOutputStream getOutputStream() 63 { 64 return new FilterServletOutputStream(output); 65 } 66 67 68 public void setContentLength(int length) 69 { 70 this.contentLength = length; 71 super.setContentLength(length); 72 } 73 74 75 public int getContentLength() 76 { 77 return contentLength; 78 } 79 80 81 public void setContentType(String type) 82 { 83 this.contentType = type; 84 super.setContentType(type); 85 } 86 87 88 public String getContentType() 89 { 90 return contentType; 91 } 92 93 94 public PrintWriter getWriter() 95 { 96 return new PrintWriter (getOutputStream(), true); 97 } 98 } 99 100 101 | Popular Tags |