1 37 package net.sourceforge.cruisecontrol.mock; 38 39 import java.io.IOException ; 40 import java.io.PrintWriter ; 41 import java.io.Reader ; 42 import java.io.StringReader ; 43 import java.io.StringWriter ; 44 import java.io.Writer ; 45 import javax.servlet.jsp.tagext.BodyContent ; 46 47 51 public class MockBodyContent extends BodyContent { 52 private final StringWriter writer = new StringWriter (); 53 private final PrintWriter printer = new PrintWriter (writer); 54 55 public MockBodyContent() { 56 super(null); 57 } 58 59 public void close() { 60 printer.close(); 61 } 62 63 public void write(int c) { 64 printer.write(c); 65 } 66 67 public void write(char[] buf, int off, int len) { 68 printer.write(buf, off, len); 69 } 70 71 public void write(char[] buf) { 72 printer.write(buf); 73 } 74 75 public void write(String s, int off, int len) { 76 printer.write(s, off, len); 77 } 78 79 public void write(String s) { 80 printer.write(s); 81 } 82 83 public void print(boolean b) { 84 printer.print(b); 85 } 86 87 public void print(char c) { 88 printer.print(c); 89 } 90 91 public void print(int i) { 92 printer.print(i); 93 } 94 95 public void print(long l) { 96 printer.print(l); 97 } 98 99 public void print(float f) { 100 printer.print(f); 101 } 102 103 public void print(double d) { 104 printer.print(d); 105 } 106 107 public void print(char[] s) { 108 printer.print(s); 109 } 110 111 public void print(String s) { 112 printer.print(s); 113 } 114 115 public void print(Object obj) { 116 printer.print(obj); 117 } 118 119 public void println() { 120 printer.println(); 121 } 122 123 public void println(boolean x) { 124 printer.println(x); 125 } 126 127 public void println(char x) { 128 printer.println(x); 129 } 130 131 public void println(int x) { 132 printer.println(x); 133 } 134 135 public void println(long x) { 136 printer.println(x); 137 } 138 139 public void println(float x) { 140 printer.println(x); 141 } 142 143 public void println(double x) { 144 printer.println(x); 145 } 146 147 public void println(char[] x) { 148 printer.println(x); 149 } 150 151 public void println(String x) { 152 printer.println(x); 153 } 154 155 public void println(Object x) { 156 printer.println(x); 157 } 158 159 public Reader getReader() { 160 return new StringReader (getString()); 161 } 162 163 public String getString() { 164 printer.flush(); 165 writer.flush(); 166 final String body = writer.toString(); 167 return body; 168 } 169 170 public void writeOut(Writer destWriter) throws IOException { 171 if (destWriter != null) { 172 destWriter.write(getString()); 173 } 174 } 175 176 public void newLine() throws IOException { 177 println(); 178 } 179 180 public void clear() throws IOException { 181 } 182 183 public void clearBuffer() throws IOException { 184 } 185 186 public int getRemaining() { 187 return 0; 188 } 189 190 public String toString() { 191 return getString(); 192 } 193 194 } 195 | Popular Tags |