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.InputStream;
21:
22: import javax.servlet.ServletInputStream;
23:
24: import org.springframework.util.Assert;
25:
26: /**
27: * Delegating implementation of {@link javax.servlet.ServletInputStream}.
28: *
29: * <p>Used by {@link MockHttpServletRequest}; typically not directly
30: * used for testing application controllers.
31: *
32: * @author Juergen Hoeller
33: * @since 1.0.2
34: * @see MockHttpServletRequest
35: */
36: public class DelegatingServletInputStream extends ServletInputStream {
37:
38: private final InputStream sourceStream;
39:
40: /**
41: * Create a DelegatingServletInputStream for the given source stream.
42: * @param sourceStream the source stream (never <code>null</code>)
43: */
44: public DelegatingServletInputStream(InputStream sourceStream) {
45: Assert.notNull(sourceStream,
46: "Source InputStream must not be null");
47: this .sourceStream = sourceStream;
48: }
49:
50: /**
51: * Return the underlying source stream (never <code>null</code>).
52: */
53: public final InputStream getSourceStream() {
54: return this .sourceStream;
55: }
56:
57: public int read() throws IOException {
58: return this .sourceStream.read();
59: }
60:
61: public void close() throws IOException {
62: super.close();
63: this.sourceStream.close();
64: }
65:
66: }
|