    1   /*
    2    * Copyright 2002-2004 the original author or authors.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    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.huihoo.jfox.soaf.util.filter;
    18
    19  import java.io.IOException;
    20  import java.io.InputStream;
    21
    22  import javax.servlet.ServletInputStream;
    23
    24  /***
    25   * Delegating implementation of ServletInputStream.
    26   *
    27   * <p>Used by MockHttpServletRequest; typically not
    28   * necessary for testing application controllers.
    29   *
    30   * @author Juergen Hoeller
    31   * @since 1.0.2
    32   * @see org.springframework.mock.web.MockHttpServletRequest
    33   */
    34  public class MockServletInputStream extends ServletInputStream {
    35
    36  	private final InputStream sourceStream;
    37
    38  	/***
    39  	 * Create a new DelegatingServletInputStream.
    40  	 * @param sourceStream the sourceStream InputStream
    41  	 */
    42  	public MockServletInputStream(InputStream sourceStream) {
    43  		this.sourceStream = sourceStream;
    44  	}
    45
    46  	public InputStream getSourceStream() {
    47  		return sourceStream;
    48  	}
    49
    50  	public int read() throws IOException {
    51  		return this.sourceStream.read();
    52  	}
    53
    54  	public void close() throws IOException {
    55  		super.close();
    56  		this.sourceStream.close();
    57  	}
    58
    59  }