1 5 6 package org.infohazard.maverick.util; 7 8 import java.io.*; 9 import javax.servlet.*; 10 11 13 public class ServletOutputStreamBuffer extends ServletOutputStream implements Buffer 14 { 15 17 protected String charset; 18 19 21 protected FastByteArrayOutputStream holder = new FastByteArrayOutputStream(); 22 23 26 public ServletOutputStreamBuffer(String charset) 27 { 28 this.charset = charset; 29 } 30 31 35 public boolean prefersReader() 36 { 37 return true; 38 } 39 40 42 public Reader getAsReader() throws UnsupportedEncodingException 43 { 44 if (this.charset != null) 45 return new InputStreamReader(this.holder.getInputStream(), this.charset); 46 else 47 return new InputStreamReader(this.holder.getInputStream()); 48 } 49 50 52 public String getAsString() throws UnsupportedEncodingException 53 { 54 if (this.charset != null) 55 return this.holder.toString(this.charset); 56 else 57 return this.holder.toString(); 58 } 59 60 62 public int size() 63 { 64 return this.holder.size(); 65 } 66 67 70 public void write(int b) throws IOException 71 { 72 holder.write(b); 73 } 74 } 75 | Popular Tags |