1 28 29 package com.caucho.filters; 30 31 import com.caucho.log.Log; 32 import com.caucho.server.connection.ToByteResponseStream; 33 import com.caucho.util.L10N; 34 35 import java.io.IOException ; 36 import java.io.OutputStream ; 37 import java.util.logging.Logger ; 38 39 public class FilterWrapperResponseStream extends ToByteResponseStream { 40 static final Logger log = Log.open(FilterWrapperResponseStream.class); 41 42 static final L10N L = new L10N(FilterWrapperResponseStream.class); 43 44 private CauchoResponseWrapper _response; 45 46 private OutputStream _os; 47 48 public FilterWrapperResponseStream() 49 { 50 } 51 52 public void init(CauchoResponseWrapper response) 53 { 54 _response = response; 55 _os = null; 56 } 57 58 65 protected void writeNext(byte []buf, int offset, int length, boolean isEnd) 66 throws IOException 67 { 68 OutputStream os = getStream(); 69 70 if (os != null) 71 os.write(buf, offset, length); 72 } 73 74 77 public void flush() 78 throws IOException 79 { 80 flushBuffer(); 81 82 OutputStream os = getStream(); 83 if (os != null) 84 os.flush(); 85 } 86 87 90 private OutputStream getStream() 91 throws IOException 92 { 93 if (_os != null) 94 return _os; 95 else if (_response != null) 96 _os = _response.getStream(); 97 98 return _os; 99 } 100 101 104 public void finish() 105 throws IOException 106 { 107 flushBuffer(); 108 109 113 114 _response = null; 115 _os = null; 116 } 117 118 121 public void close() 122 throws IOException 123 { 124 super.close(); 125 126 _response = null; 127 128 OutputStream os = _os; 129 _os = null; 130 132 if (os != null) 133 os.close(); 134 } 135 } 136 | Popular Tags |