com.monkeycoder.monkeynetwork
Class ConnectionSpeedTimer

java.lang.Object
  extended by com.monkeycoder.monkeynetwork.ConnectionSpeedTimer

public class ConnectionSpeedTimer
extends java.lang.Object

This class is used for tracking the download rate.

Author:
David Stephens

Constructor Summary
ConnectionSpeedTimer()
          Creates a new ConnectionSpeedTimer.
ConnectionSpeedTimer(boolean autoStart)
          Creates a new ConnectionSpeedTimer and optionally starts it.
 
Method Summary
 int getAverageSpeed(int inTotalBytes)
          Returns average speed in rounded bytes/sec.
 int getSpeed(int inTotalBytes)
          Returns instantaneous speed in rounded bytes/sec.
 void start()
          Starts the timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionSpeedTimer

public ConnectionSpeedTimer()
Creates a new ConnectionSpeedTimer.


ConnectionSpeedTimer

public ConnectionSpeedTimer(boolean autoStart)
Creates a new ConnectionSpeedTimer and optionally starts it.

Parameters:
autoStart - Whether or not to automatically start the timer immediately upon creation.
Method Detail

start

public void start()
Starts the timer.


getSpeed

public int getSpeed(int inTotalBytes)
Returns instantaneous speed in rounded bytes/sec. This is based on the difference in bytes and time since either the start of the timer or the last time this method was called.

Parameters:
inTotalBytes - The number of bytes that have been received.
Returns:
Instantaneous speed in bytes/sec.

getAverageSpeed

public int getAverageSpeed(int inTotalBytes)
Returns average speed in rounded bytes/sec. This is based on the total number of bytes over the entire time since the start of the timer. This method of calculation may result in eratic speed reports until a sufficient amount of time has elapsed but will "settle down" over time.

Parameters:
inTotalBytes - The number of bytes that have been received.
Returns:
Average speed in bytes/sec.