01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.mock.web;
18:
19: import java.io.IOException;
20: import java.io.OutputStream;
21:
22: import javax.servlet.ServletOutputStream;
23:
24: import org.springframework.util.Assert;
25:
26: /**
27: * Delegating implementation of {@link javax.servlet.ServletOutputStream}.
28: *
29: * <p>Used by {@link MockHttpServletResponse}; typically not directly
30: * used for testing application controllers.
31: *
32: * @author Juergen Hoeller
33: * @since 1.0.2
34: * @see MockHttpServletResponse
35: */
36: public class DelegatingServletOutputStream extends ServletOutputStream {
37:
38: private final OutputStream targetStream;
39:
40: /**
41: * Create a DelegatingServletOutputStream for the given target stream.
42: * @param targetStream the target stream (never <code>null</code>)
43: */
44: public DelegatingServletOutputStream(OutputStream targetStream) {
45: Assert.notNull(targetStream,
46: "Target OutputStream must not be null");
47: this .targetStream = targetStream;
48: }
49:
50: /**
51: * Return the underlying target stream (never <code>null</code>).
52: */
53: public final OutputStream getTargetStream() {
54: return this .targetStream;
55: }
56:
57: public void write(int b) throws IOException {
58: this .targetStream.write(b);
59: }
60:
61: public void flush() throws IOException {
62: super .flush();
63: this .targetStream.flush();
64: }
65:
66: public void close() throws IOException {
67: super.close();
68: this.targetStream.close();
69: }
70:
71: }
|