636b792051
the JNLP versioned resource protocol so that it can download jardiffs instead of whole new jar files when a resource bundle is updated. Unversioned http downloads (which we'll probably continue to use for the dynamically generated island bundles) are currently not working. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2739 542714f4-19e9-0310-aa3c-eee0fc999fb1
61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
//
|
|
// $Id: ProgressInfo.java,v 1.1 2003/08/05 01:33:20 mdb Exp $
|
|
|
|
package com.threerings.resource;
|
|
|
|
/**
|
|
* Used to track download progress.
|
|
*/
|
|
public class ProgressInfo
|
|
{
|
|
/** The total file size in bytes to be transferred. */
|
|
public long totalSize;
|
|
|
|
/** The file size in bytes transferred thus far. */
|
|
public long currentSize;
|
|
|
|
/** The time at which the file transfer began. */
|
|
public long start;
|
|
|
|
/** The current transfer rate in bytes per second. */
|
|
public long bytesPerSecond;
|
|
|
|
/** The time at which the last progress update was posted to the
|
|
* progress observer. */
|
|
public long lastUpdate;
|
|
|
|
/** Whether the download has completed and the progress observer
|
|
* notified. */
|
|
public boolean complete;
|
|
|
|
/**
|
|
* Returns the percent completion, based on data size transferred,
|
|
* of the file transfer.
|
|
*/
|
|
public int getPercentDone ()
|
|
{
|
|
return (int)((currentSize / (float)totalSize) * 100f);
|
|
}
|
|
|
|
/**
|
|
* Updates the bytes per second transfer rate for the download
|
|
* associated with this progress info record.
|
|
*/
|
|
public void updateXferRate (long now)
|
|
{
|
|
long secs = (now - start) / 1000L;
|
|
bytesPerSecond = (secs == 0) ? 0 : (currentSize / secs);
|
|
}
|
|
|
|
/**
|
|
* Returns the estimated transfer time remaining for the download
|
|
* associated with this progress info record, or <code>-1</code> if
|
|
* the transfer time cannot currently be estimated.
|
|
*/
|
|
public long getXferTimeRemaining ()
|
|
{
|
|
return (bytesPerSecond == 0) ? -1 :
|
|
(totalSize - currentSize) / bytesPerSecond;
|
|
}
|
|
}
|