net.sf.zig_project.gpl.simulation
Class SlowOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended bynet.sf.zig_project.gpl.simulation.SlowOutputStream

public class SlowOutputStream
extends FilterOutputStream

The SlowOutputStream class slows down a given OutputStream. This prevents the given OutputStream 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, in nanoseconds per Byte
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
SlowOutputStream(OutputStream out, double BpS)
          Creates a SlowOutput emulator.
 
Method Summary
 void write(byte[] buf, int off, int len)
          Writes a block of data.
 void write(int b)
          Writes a single byte of data.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nSpB

protected final double nSpB
Delay time, in nanoseconds per Byte

Constructor Detail

SlowOutputStream

public SlowOutputStream(OutputStream out,
                        double BpS)
Creates a SlowOutput emulator.

Parameters:
out - the OutputStream to slow down
BpS - the data rate to emulate, in Bytes / second
Method Detail

write

public void write(int b)
           throws IOException
Writes a single byte of data. This method will pause long enough to emulate a slower speed as specified. Presently, this method does not account for the time required for the current thread to obtain a lock on the OutputStream. It is recommended that this OutputStream be buffered, instead of calling this method directly, in order to provide more accurate timing.

Throws:
IOException

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws IOException
Writes a block of data. The OutputStream will pause long enough to emulate a slower speed as specified.

Throws:
IOException