001 package railo.commons.io; 002 003 import java.io.IOException; 004 import java.io.Writer; 005 006 public class ForkWriter extends Writer { 007 008 private final Writer w1; 009 private final Writer w2; 010 011 public ForkWriter(Writer w1, Writer w2) { 012 this.w1=w1; 013 this.w2=w2; 014 } 015 016 /** 017 * 018 * @see java.io.Writer#append(char) 019 */ 020 public Writer append(char c) throws IOException { 021 try { 022 w1.write(c); 023 } 024 finally { 025 w2.write(c); 026 } 027 return this; 028 } 029 030 /** 031 * 032 * @see java.io.Writer#append(java.lang.CharSequence, int, int) 033 */ 034 public Writer append(CharSequence csq, int start, int end) throws IOException { 035 try { 036 w1.write(csq.toString(), start, end); 037 } 038 finally { 039 w2.write(csq.toString(), start, end); 040 } 041 return this; 042 } 043 044 /** 045 * 046 * @see java.io.Writer#append(java.lang.CharSequence) 047 */ 048 public Writer append(CharSequence csq) throws IOException { 049 try { 050 w1.write(csq.toString()); 051 } 052 finally { 053 w2.write(csq.toString()); 054 } 055 return this; 056 } 057 058 /** 059 * 060 * @see java.io.Writer#write(char[]) 061 */ 062 public void write(char[] cbuf) throws IOException { 063 try { 064 w1.write(cbuf); 065 } 066 finally { 067 w2.write(cbuf); 068 } 069 } 070 071 /** 072 * 073 * @see java.io.Writer#write(int) 074 */ 075 public void write(int c) throws IOException { 076 try { 077 w1.write(c); 078 } 079 finally { 080 w2.write(c); 081 } 082 } 083 084 /** 085 * 086 * @see java.io.Writer#write(java.lang.String, int, int) 087 */ 088 public void write(String str, int off, int len) throws IOException { 089 try { 090 w1.write(str, off, len); 091 } 092 finally { 093 w2.write(str, off, len); 094 } 095 } 096 097 /** 098 * 099 * @see java.io.Writer#write(java.lang.String) 100 */ 101 public void write(String str) throws IOException { 102 try { 103 w1.write(str); 104 } 105 finally { 106 w2.write(str); 107 } 108 } 109 110 /** 111 * 112 * @see java.io.Writer#close() 113 */ 114 public void close() throws IOException { 115 try { 116 w1.close(); 117 } 118 finally { 119 w2.close(); 120 } 121 } 122 123 /** 124 * 125 * @see java.io.Writer#flush() 126 */ 127 public void flush() throws IOException { 128 129 try { 130 w1.flush(); 131 } 132 finally { 133 w2.flush(); 134 } 135 } 136 137 /** 138 * 139 * @see java.io.Writer#write(char[], int, int) 140 */ 141 public void write(char[] cbuf, int off, int len) throws IOException { 142 143 try { 144 w1.write(cbuf, off, len); 145 } 146 finally { 147 w2.write(cbuf, off, len); 148 } 149 } 150 151 }