01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.util;
20:
21: import java.io.FilterInputStream;
22: import java.io.IOException;
23: import java.io.InputStream;
24:
25: /**
26: * InputStream wrapper to emulate a slow device, e.g. modem
27: *
28: */
29: public class SlowInputStream extends FilterInputStream {
30:
31: private final CPSPauser pauser;
32:
33: /**
34: * Wraps the input stream to emulate a slow device
35: * @param in input stream
36: * @param cps characters per second to emulate
37: */
38: public SlowInputStream(InputStream in, int cps) {
39: super (in);
40: pauser = new CPSPauser(cps);
41: }
42:
43: public int read() throws IOException {
44: pauser.pause(1);
45: return in.read();
46: }
47:
48: // Also handles read(byte[])
49: public int read(byte[] b, int off, int len) throws IOException {
50: pauser.pause(len);
51: return in.read(b, off, len);
52: }
53:
54: }
|