UploadStatus.java

com.mojang.realmsclient.client.UploadStatus

信息

  • 全限定名:com.mojang.realmsclient.client.UploadStatus
  • 类型:public class
  • 包:com.mojang.realmsclient.client
  • 源码路径:src/main/java/com/mojang/realmsclient/client/UploadStatus.java
  • 起始行号:L8
  • 职责:

    TODO

字段/常量

  • bytesWritten

    • 类型: long
    • 修饰符: private volatile
    • 源码定位: L9
    • 说明:

      TODO

  • totalBytes

    • 类型: long
    • 修饰符: private volatile
    • 源码定位: L10
    • 说明:

      TODO

  • previousTimeSnapshot

    • 类型: long
    • 修饰符: private
    • 源码定位: L11
    • 说明:

      TODO

  • previousBytesWritten

    • 类型: long
    • 修饰符: private
    • 源码定位: L12
    • 说明:

      TODO

  • bytesPerSecond

    • 类型: long
    • 修饰符: private
    • 源码定位: L13
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public void setTotalBytes(long totalBytes) @ L15

  • 方法名:setTotalBytes
  • 源码定位:L15
  • 返回类型:void
  • 修饰符:public

参数:

  • totalBytes: long

说明:

TODO

public void restart() @ L19

  • 方法名:restart
  • 源码定位:L19
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public long getTotalBytes() @ L26

  • 方法名:getTotalBytes
  • 源码定位:L26
  • 返回类型:long
  • 修饰符:public

参数:

说明:

TODO

public long getBytesWritten() @ L30

  • 方法名:getBytesWritten
  • 源码定位:L30
  • 返回类型:long
  • 修饰符:public

参数:

说明:

TODO

public void onWrite(long bytesWritten) @ L34

  • 方法名:onWrite
  • 源码定位:L34
  • 返回类型:void
  • 修饰符:public

参数:

  • bytesWritten: long

说明:

TODO

public boolean uploadStarted() @ L38

  • 方法名:uploadStarted
  • 源码定位:L38
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean uploadCompleted() @ L42

  • 方法名:uploadCompleted
  • 源码定位:L42
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public double getPercentage() @ L46

  • 方法名:getPercentage
  • 源码定位:L46
  • 返回类型:double
  • 修饰符:public

参数:

说明:

TODO

public void refreshBytesPerSecond() @ L50

  • 方法名:refreshBytesPerSecond
  • 源码定位:L50
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public long getBytesPerSecond() @ L61

  • 方法名:getBytesPerSecond
  • 源码定位:L61
  • 返回类型:long
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class UploadStatus {
    private volatile long bytesWritten;
    private volatile long totalBytes;
    private long previousTimeSnapshot = Util.getMillis();
    private long previousBytesWritten;
    private long bytesPerSecond;
 
    public void setTotalBytes(long totalBytes) {
        this.totalBytes = totalBytes;
    }
 
    public void restart() {
        this.bytesWritten = 0L;
        this.previousTimeSnapshot = Util.getMillis();
        this.previousBytesWritten = 0L;
        this.bytesPerSecond = 0L;
    }
 
    public long getTotalBytes() {
        return this.totalBytes;
    }
 
    public long getBytesWritten() {
        return this.bytesWritten;
    }
 
    public void onWrite(long bytesWritten) {
        this.bytesWritten = bytesWritten;
    }
 
    public boolean uploadStarted() {
        return this.bytesWritten > 0L;
    }
 
    public boolean uploadCompleted() {
        return this.bytesWritten >= this.totalBytes;
    }
 
    public double getPercentage() {
        return Math.min((double)this.getBytesWritten() / this.getTotalBytes(), 1.0);
    }
 
    public void refreshBytesPerSecond() {
        long currentMillis = Util.getMillis();
        long timeElapsed = currentMillis - this.previousTimeSnapshot;
        if (timeElapsed >= 1000L) {
            long bytesWritten = this.bytesWritten;
            this.bytesPerSecond = 1000L * (bytesWritten - this.previousBytesWritten) / timeElapsed;
            this.previousBytesWritten = bytesWritten;
            this.previousTimeSnapshot = currentMillis;
        }
    }
 
    public long getBytesPerSecond() {
        return this.bytesPerSecond;
    }
}

引用的其他类

  • Util
    • 引用位置: 方法调用
    • 关联成员: Util.getMillis()