1   package servletunit;
2   
3   //  StrutsTestCase - a JUnit extension for testing Struts actions
4   //  within the context of the ActionServlet.
5   //  Copyright (C) 2002 Deryl Seale
6   //
7   //  This library is free software; you can redistribute it and/or
8   //  modify it under the terms of the Apache Software License as
9   //  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  {
25      private OutputStream outStream;
26      
27      /**
28       * Default constructor that sends all output to <code>System.out</code>.
29       */
30      public ServletOutputStreamSimulator()
31      {
32          this.outStream = System.out;
33      }
34      
35      /**
36       * Constructor that sends all output to given OutputStream.
37       * @param out OutputStream to which all output will be sent.
38       */
39      public ServletOutputStreamSimulator( OutputStream out )
40      {
41          this.outStream = out;
42      }
43      
44      public void write( int b )
45      {
46          try
47          {
48          outStream.write( b );
49          }
50          catch( IOException io )
51          {
52          System.err.println("IOException: " + io.getMessage());
53          io.printStackTrace();
54          }
55      }
56  }