1 3 package jodd.servlet.filter; 4 5 import java.io.PrintWriter ; 6 7 import javax.servlet.ServletOutputStream ; 8 import javax.servlet.http.HttpServletResponse ; 9 import javax.servlet.http.HttpServletResponseWrapper ; 10 11 import jodd.util.CharUtil; 12 import jodd.io.FastCharArrayWriter; 13 14 18 public class CharArrayResponseWrapper extends HttpServletResponseWrapper { 19 20 private FastCharArrayWriter writer; 21 22 32 public CharArrayResponseWrapper(HttpServletResponse response) { 33 super(response); 34 writer = new FastCharArrayWriter(); 35 } 36 37 43 public PrintWriter getWriter() { 44 return new PrintWriter (writer); 45 } 46 47 54 public String toString() { 55 return writer.toString(); 56 } 57 58 61 public char[] toCharArray() { 62 return writer.toCharArray(); 63 } 64 65 68 public byte[] toByteArray() { 69 return CharUtil.toByteArray(writer.toCharArray()); 70 } 71 72 73 76 public void setContentLength(int len) { 77 super.setContentLength(len); 78 } 79 80 83 public int getSize() { 84 return writer.size(); 85 } 86 87 88 private String contentType = ""; 89 90 93 public void setContentType(String type) { 94 super.setContentType(type); 95 contentType = type; 96 } 97 98 101 public String getContentType() { 102 return contentType; 103 } 104 105 public void close() { 106 writer.close(); 107 } 108 109 public void reset() { 110 writer.reset(); 111 } 112 113 116 public ServletOutputStream getOutputStream() { 117 118 return new ServletOutputStream () { 119 public void write(int b) { 120 writer.write(b); 121 } 122 123 public void write(byte b[]) { 124 writer.write(CharUtil.toCharArray(b), 0, b.length); 125 } 126 127 public void write(byte b[], int off, int len) { 128 writer.write(CharUtil.toCharArray(b), off, len); 129 } 130 }; 131 } 132 133 } 134 | Popular Tags |