dist1.acb.common.transport
Class FlowRateInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bydist1.acb.common.transport.FlowRateInputStream

public class FlowRateInputStream
extends java.io.FilterInputStream

Stream which measures flow rate.

Version:
$Revision: 1.5 $
Author:
Alexander Stasiv

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
FlowRateInputStream(java.io.InputStream in)
          Creates a new instance of FlowRateInputStream; measureInterval = 1000ms
 
Method Summary
 long getCurrentRate()
          Calculates the overal rate (in byte/sec)
 java.lang.String getCurrentRateFormated()
          Calculates the overal rate (in Kbyte/sec) and returns it as String "#.##"
 long getOverallRate()
          Calculates the current rate (in byte/sec)
 java.lang.String getOverallRateFormated()
          Calculates the current rate (in Kbyte/sec) and returns it as String "#.##"
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b)
          Reads up to byte.length bytes of data from this input stream into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
 void startMeasuring()
          Start measuring with default interval 1000 ms
 void startMeasuring(int measureInterval)
          Start measuring
 void stopMeasuring()
          Stop measuring
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlowRateInputStream

public FlowRateInputStream(java.io.InputStream in)
Creates a new instance of FlowRateInputStream; measureInterval = 1000ms

Parameters:
in - underlaying input stream to be measured
Method Detail

getCurrentRate

public long getCurrentRate()
Calculates the overal rate (in byte/sec)

Returns:
the mean rate on the last measureInterval milliseconds

getCurrentRateFormated

public java.lang.String getCurrentRateFormated()
Calculates the overal rate (in Kbyte/sec) and returns it as String "#.##"

Returns:
the mean rate on the last measureInterval milliseconds

getOverallRate

public long getOverallRate()
Calculates the current rate (in byte/sec)

Returns:
the mean rate since the stream is open

getOverallRateFormated

public java.lang.String getOverallRateFormated()
Calculates the current rate (in Kbyte/sec) and returns it as String "#.##"

Returns:
the mean rate since the stream is open

read

public int read()
         throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

This method simply performs in.read() and returns the result.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.in

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

This method simply performs in.read(b, off, len) and returns the result.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.in

read

public int read(byte[] b)
         throws java.io.IOException
Reads up to byte.length bytes of data from this input stream into an array of bytes.

Parameters:
b - the buffer into which the data is read
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
Throws:
java.io.IOException - if an I/O error occurs

startMeasuring

public void startMeasuring(int measureInterval)
Start measuring

Parameters:
measureInterval - duration between two measures (in milliseconds). 0 means you don't want to see current rate trace (and don't want one more Thread). In this case, you cannot call currentRate()

startMeasuring

public void startMeasuring()
Start measuring with default interval 1000 ms


stopMeasuring

public void stopMeasuring()
Stop measuring



Copyright © 2004 Phoenix Team (CMU/AIT). All Rights Reserved.