1 24 package org.riotfamily.cachius.support; 25 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 29 import javax.servlet.ServletOutputStream ; 30 31 37 public class MultiplexServletOutputStream extends ServletOutputStream { 38 39 private OutputStream out1 = null; 40 41 private OutputStream out2 = null; 42 43 private boolean clientAbort = false; 44 45 51 public MultiplexServletOutputStream(OutputStream out1, 52 ServletOutputStream out2) { 53 54 this.out1 = out1; 55 this.out2 = out2; 56 } 57 58 64 public void write(int value) throws IOException { 65 out1.write(value); 66 try { 67 if (!clientAbort) { 68 out2.write(value); 69 } 70 } 71 catch (IOException e) { 72 clientAbort = true; 73 } 74 } 75 76 82 public void write(byte[] value) throws IOException { 83 out1.write(value); 84 try { 85 if (!clientAbort) { 86 out2.write(value); 87 } 88 } 89 catch (IOException e) { 90 clientAbort = true; 91 } 92 } 93 94 102 public void write(byte[] b, int off, int len) throws IOException { 103 out1.write(b, off, len); 104 try { 105 if (!clientAbort) { 106 out2.write(b, off, len); 107 } 108 } 109 catch (IOException e) { 110 clientAbort = true; 111 } 112 } 113 114 117 public void flush() throws IOException { 118 out1.flush(); 119 try { 120 if (!clientAbort) { 121 out2.flush(); 122 } 123 } 124 catch (IOException e) { 125 clientAbort = true; 126 } 127 } 128 129 132 public void close() throws IOException { 133 out1.close(); 134 out2.close(); 135 } 136 137 } 138 | Popular Tags |