Save This Page
Home » openjdk-7 » net.bonzoun » cocodonkey » [javadoc | source]
    1   //
    2   //  BlocSpeed.java
    3   //  CocoDonkey
    4   //  $Id: UploadSpeed.java,v 1.2 2002/08/21 21:50:22 fortun Exp $
    5   //
    6   //  Created by Fred Bonzoun on Sun May 19 2002.
    7   //  Copyright (c) 2002 Bonzoun. All rights reserved.
    8   //
    9   //  This library is free software; you can redistribute it and/or modify
   10   //  it under the terms of the GNU Lesser General Public License as published
   11   //  by the Free Software Foundation; either version 2.1 of the License, or
   12   //  (at your option) any later version.
   13   //
   14   //  This library is distributed in the hope that it will be useful,
   15   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17   //  GNU Lesser General Public License for more details.
   18   //
   19   //  You should have received a copy of the GNU Lesser General Public License
   20   //  along with this program; if not, write to the Free Software
   21   //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   22   //
   23   
   24   package net.bonzoun.cocodonkey;
   25   
   26   public class UploadSpeed {
   27   
   28       private int initBlocCount;
   29       private long initTime;
   30       private int curBlocCount;
   31       private long curTime;
   32   
   33       public UploadSpeed() {
   34       }
   35   
   36       public int blocSize() {
   37           return 8000;
   38       }
   39   
   40       public void setBytesCount(int n) {
   41           setBlocCount(n/blocSize());
   42       }
   43       
   44       public void setBlocCount(int n) {
   45           long t = System.currentTimeMillis();
   46           if (curTime==0 || t-curTime > 10000) {
   47               initBlocCount = curBlocCount;
   48               initTime = curTime;
   49               curBlocCount = n;
   50               curTime = System.currentTimeMillis();
   51           }
   52       }
   53   
   54       public double speed() {
   55           if (initTime==0)
   56               return -1;
   57           return (curBlocCount-initBlocCount)*(float)blocSize()/(curTime-initTime);
   58       }
   59   }
   60   
   61   // $Log: UploadSpeed.java,v $
   62   // Revision 1.2  2002/08/21 21:50:22  fortun
   63   // Handles bytes instead of blocs
   64   //
   65   // Revision 1.1.1.1  2002/05/21 21:26:13  fortun
   66   //
   67   //

Save This Page
Home » openjdk-7 » net.bonzoun » cocodonkey » [javadoc | source]