net.sf.zig_project.gpl.simulation
Class SlowInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
net.sf.zig_project.gpl.simulation.SlowInputStream
- public class SlowInputStream
- extends FilterInputStream
The SlowInputStream class slows down a given InputStream. This prevents the
given InputStream from returning as soon as it is completed. Hence, the
behavior of this stream is to operate as slowly (or possibly slower) than
the specified data rate.
This class is used within the Simulation package, and hence is designed
for configuring simulated test environments, not for precision timing.
- Version:
- September 24, 2004
- Author:
- Frank Ziglar
Field Summary |
protected double |
nSpB
delay time, measured in Nanoseconds per Byte |
Method Summary |
int |
read()
Reads a single byte of data from the underlying
InputStream. |
int |
read(byte[] buf,
int off,
int len)
Reads data into the buffer from the underlying
InputStream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
nSpB
protected final double nSpB
- delay time, measured in Nanoseconds per Byte
SlowInputStream
public SlowInputStream(InputStream is,
double BpS)
- Creates a SlowInputStream layer.
- Parameters:
is
- the InputStream to load data fromBpS
- the data rate to emulate, in Bytes / sec
read
public int read()
throws IOException
- Reads a single byte of data from the underlying
InputStream. This method will pause at the rate
of 1 / the constructed paramater BpS until the
end of the stream is reached. It is however,
recommended that this stream be buffered, instead
of calling this method directly, in order for
timing to be conducted more accurately.
- Throws:
IOException
read
public int read(byte[] buf,
int off,
int len)
throws IOException
- Reads data into the buffer from the underlying
InputStream. This method will pause
based on the amount of data actually loaded to
emulate the fixed data rate. If the stream has
been ended, this method will return immediately.
- Throws:
IOException