001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.test.mock;
016    
017    import java.io.FileInputStream;
018    import java.io.IOException;
019    import java.io.InputStream;
020    
021    import javax.servlet.ServletInputStream;
022    
023    /**
024     * Implementation of {@link ServletInputStream} used in mock object testing.
025     * The data in the stream is provided by a binary file.  The implemenation
026     * wraps around a {@link java.io.FileInputStream} redirecting all method
027     * invocations to the inner stream.
028     *
029     * @author Howard Lewis Ship
030     * @since 4.0
031     */
032    
033    public class MockServletInputStream extends ServletInputStream
034    {
035        private InputStream _inner;
036    
037        public MockServletInputStream(String path) throws IOException
038        {
039            _inner = new FileInputStream(path);
040        }
041    
042        public int read() throws IOException
043        {
044            return _inner.read();
045        }
046    
047        public int available() throws IOException
048        {
049            return _inner.available();
050        }
051    
052        public void close() throws IOException
053        {
054            _inner.close();
055        }
056    
057        public synchronized void mark(int readlimit)
058        {
059            _inner.mark(readlimit);
060        }
061    
062        public boolean markSupported()
063        {
064            return _inner.markSupported();
065        }
066    
067        public int read(byte[] b, int off, int len) throws IOException
068        {
069            return _inner.read(b, off, len);
070        }
071    
072        public int read(byte[] b) throws IOException
073        {
074            return _inner.read(b);
075        }
076    
077        public synchronized void reset() throws IOException
078        {
079            _inner.reset();
080        }
081    
082        public long skip(long n) throws IOException
083        {
084            return _inner.skip(n);
085        }
086    
087    }