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.FilterOutputStream;
22: import java.io.IOException;
23: import java.io.OutputStream;
24:
25: /**
26: * OutputStream filter to emulate a slow device, e.g. modem
27: *
28: */
29: public class SlowOutputStream extends FilterOutputStream {
30:
31: private final CPSPauser pauser;
32:
33: /**
34: * Create wrapped Output Stream toe emulate the requested CPS.
35: * @param out OutputStream
36: * @param cps characters per second
37: */
38: public SlowOutputStream(OutputStream out, int cps) {
39: super (out);
40: pauser = new CPSPauser(cps);
41: }
42:
43: // Also handles write(byte[])
44: public void write(byte[] b, int off, int len) throws IOException {
45: pauser.pause(len);
46: out.write(b, off, len);
47: }
48:
49: public void write(int b) throws IOException {
50: pauser.pause(1);
51: out.write(b);
52: }
53: }
|