1 24 package org.jresearch.gossip.filters.cache; 25 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 29 import javax.servlet.ServletOutputStream ; 30 import javax.servlet.http.HttpServletResponse ; 31 32 public class CacheResponseStream extends ServletOutputStream { 33 34 protected boolean closed = false; 35 36 protected HttpServletResponse response = null; 37 38 protected ServletOutputStream output = null; 39 40 protected OutputStream cache = null; 41 42 public CacheResponseStream(HttpServletResponse response, OutputStream cache) 43 throws IOException { 44 super(); 45 closed = false; 46 this.response = response; 47 this.cache = cache; 48 } 49 50 public void close() throws IOException { 51 if (closed) { 52 throw new IOException ("This output stream has already been closed"); 53 } 54 cache.close(); 55 closed = true; 56 } 57 58 public void flush() throws IOException { 59 if (closed) { 60 throw new IOException ("Cannot flush a closed output stream"); 61 } 62 cache.flush(); 63 } 64 65 public void write(int b) throws IOException { 66 if (closed) { 67 throw new IOException ("Cannot write to a closed output stream"); 68 } 69 cache.write((byte) b); 70 } 71 72 public void write(byte b[]) throws IOException { 73 write(b, 0, b.length); 74 } 75 76 public void write(byte b[], int off, int len) throws IOException { 77 if (closed) { 78 throw new IOException ("Cannot write to a closed output stream"); 79 } 80 cache.write(b, off, len); 81 } 82 83 public boolean closed() { 84 return (this.closed); 85 } 86 87 public void reset() { 88 } 90 } | Popular Tags |