2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.test.mock;
19
20 import java.io.ByteArrayOutputStream;
21 import javax.servlet.ServletOutputStream;
22
23 /***
24 * <p>Mock implementation of <code>ServletOutputStream</code>.</p>
25 *
26 * $Id: MockServletOutputStream.java 464373 2006-10-16 04:21:54Z rahul $
27 */
28
29 public class MockServletOutputStream extends ServletOutputStream {
30
31
32
33
34
35 /***
36 * <p>Return a default instance.</p>
37 *
38 * @param stream The stream we will use to buffer output
39 */
40 public MockServletOutputStream(ByteArrayOutputStream stream) {
41 this.baos = stream;
42 }
43
44
45
46
47
48 /***
49 * <p>Return the content that has been written to this output stream.</p>
50 */
51 public byte[] content() {
52 return baos.toByteArray();
53 }
54
55
56 /***
57 * <p>Reset this output stream so that it appears no content has been
58 * written.</p>
59 */
60 public void reset() {
61 baos.reset();
62 }
63
64
65 /***
66 * <p>Return the number of bytes that have been written to this output stream.</p>
67 */
68 public int size() {
69 return baos.size();
70 }
71
72
73
74
75
76
77 /***
78 * <p>The internal buffer we use to capture output.</p>
79 */
80 private ByteArrayOutputStream baos = null;
81
82
83
84
85
86 /***
87 * <p>Write the specified content to our internal cache.</p>
88 *
89 * @param content Content to be written
90 */
91 public void write(int content) {
92 baos.write(content);
93 }
94
95
96 }