KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > mock > MockBodyContent


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.mock;
38
39 import java.io.IOException JavaDoc;
40 import java.io.PrintWriter JavaDoc;
41 import java.io.Reader JavaDoc;
42 import java.io.StringReader JavaDoc;
43 import java.io.StringWriter JavaDoc;
44 import java.io.Writer JavaDoc;
45 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
46
47 /**
48  *
49  * @author <a HREF="mailto:robertdw@sourceforge.net">Robert Watkins</a>
50  */

51 public class MockBodyContent extends BodyContent JavaDoc {
52     private final StringWriter JavaDoc writer = new StringWriter JavaDoc();
53     private final PrintWriter JavaDoc printer = new PrintWriter JavaDoc(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 JavaDoc s, int off, int len) {
76         printer.write(s, off, len);
77     }
78
79     public void write(String JavaDoc 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 JavaDoc s) {
112         printer.print(s);
113     }
114
115     public void print(Object JavaDoc 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 JavaDoc x) {
152         printer.println(x);
153     }
154
155     public void println(Object JavaDoc x) {
156         printer.println(x);
157     }
158
159     public Reader JavaDoc getReader() {
160         return new StringReader JavaDoc(getString());
161     }
162
163     public String JavaDoc getString() {
164         printer.flush();
165         writer.flush();
166         final String JavaDoc body = writer.toString();
167         return body;
168     }
169
170     public void writeOut(Writer JavaDoc destWriter) throws IOException JavaDoc {
171         if (destWriter != null) {
172             destWriter.write(getString());
173         }
174     }
175
176     public void newLine() throws IOException JavaDoc {
177         println();
178     }
179
180     public void clear() throws IOException JavaDoc {
181     }
182
183     public void clearBuffer() throws IOException JavaDoc {
184     }
185
186     public int getRemaining() {
187         return 0;
188     }
189
190     public String JavaDoc toString() {
191         return getString();
192     }
193
194 }
195
Popular Tags