01: package servletunit;
02:
03: // StrutsTestCase - a JUnit extension for testing Struts actions
04: // within the context of the ActionServlet.
05: // Copyright (C) 2002 Deryl Seale
06: //
07: // This library is free software; you can redistribute it and/or
08: // modify it under the terms of the Apache Software License as
09: // published by the Apache Software Foundation; either version 1.1
10: // of the License, or (at your option) any later version.
11: //
12: // This library is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // Apache Software Foundation Licens for more details.
16: //
17: // You may view the full text here: http://www.apache.org/LICENSE.txt
18:
19: import javax.servlet.ServletOutputStream;
20: import java.io.IOException;
21: import java.io.OutputStream;
22:
23: public class ServletOutputStreamSimulator extends ServletOutputStream {
24: private OutputStream outStream;
25:
26: /**
27: * Default constructor that sends all output to <code>System.out</code>.
28: */
29: public ServletOutputStreamSimulator() {
30: this .outStream = System.out;
31: }
32:
33: /**
34: * Constructor that sends all output to given OutputStream.
35: * @param out OutputStream to which all output will be sent.
36: */
37: public ServletOutputStreamSimulator(OutputStream out) {
38: this .outStream = out;
39: }
40:
41: public void write(int b) {
42: try {
43: outStream.write(b);
44: } catch (IOException io) {
45: System.err.println("IOException: " + io.getMessage());
46: io.printStackTrace();
47: }
48: }
49: }
|