KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > test > mock > MockServletInputStream


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.test.mock;
16
17 import java.io.FileInputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20
21 import javax.servlet.ServletInputStream JavaDoc;
22
23 /**
24  * Implementation of {@link ServletInputStream} used in mock object testing.
25  * The data in the stream is provided by a binary file. The implemenation
26  * wraps around a {@link java.io.FileInputStream} redirecting all method
27  * invocations to the inner stream.
28  *
29  * @author Howard Lewis Ship
30  * @since 4.0
31  */

32
33 public class MockServletInputStream extends ServletInputStream JavaDoc
34 {
35     private InputStream JavaDoc _inner;
36
37     public MockServletInputStream(String JavaDoc path) throws IOException JavaDoc
38     {
39         _inner = new FileInputStream JavaDoc(path);
40     }
41
42     public int read() throws IOException JavaDoc
43     {
44         return _inner.read();
45     }
46
47     public int available() throws IOException JavaDoc
48     {
49         return _inner.available();
50     }
51
52     public void close() throws IOException JavaDoc
53     {
54         _inner.close();
55     }
56
57     public synchronized void mark(int readlimit)
58     {
59         _inner.mark(readlimit);
60     }
61
62     public boolean markSupported()
63     {
64         return _inner.markSupported();
65     }
66
67     public int read(byte[] b, int off, int len) throws IOException JavaDoc
68     {
69         return _inner.read(b, off, len);
70     }
71
72     public int read(byte[] b) throws IOException JavaDoc
73     {
74         return _inner.read(b);
75     }
76
77     public synchronized void reset() throws IOException JavaDoc
78     {
79         _inner.reset();
80     }
81
82     public long skip(long n) throws IOException JavaDoc
83     {
84         return _inner.skip(n);
85     }
86
87 }
88
Popular Tags