Record Class UploadProgress

java.lang.Object
java.lang.Record
cloud.opencode.base.io.progress.UploadProgress
Record Components:
fileName - the file name being uploaded - 正在上传的文件名
bytesUploaded - bytes uploaded so far - 迄今已上传的字节数
totalBytes - total bytes to upload (may be 0 if unknown) - 要上传的总字节数(未知时为 0)
elapsedMs - elapsed time in milliseconds since the upload started - 上传开始以来的耗时(毫秒)

public record UploadProgress(String fileName, long bytesUploaded, long totalBytes, long elapsedMs) extends Record
Upload Progress - Snapshot of an upload operation's current progress 上传进度 - 上传操作当前进度的快照

Passed to the progress listener callback at regular intervals during an upload. All fields are immutable since this is a point-in-time snapshot.

上传期间定期传递给进度监听器回调。所有字段不可变,因为这是某一时刻的快照。

Features | 主要功能:

  • Upload progress snapshot with file name and bytes - 上传进度快照(文件名和字节数)
  • Throughput calculation in bytes per second - 每秒字节数吞吐量计算
  • Formatted percentage output - 格式化百分比输出

Usage Examples | 使用示例:

UploadProgress progress = new UploadProgress("data.zip", 500000, 1000000, 5000);
System.out.println(progress.formattedPercentage());  // "50.0%"
System.out.println(progress.throughputBytesPerSec()); // 100000.0

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No, fileName must not be null - 空值安全: 否,fileName不可为null
Since:
JDK 25, opencode-base-io V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • UploadProgress

      public UploadProgress(String fileName, long bytesUploaded, long totalBytes, long elapsedMs)
      Creates an instance of a UploadProgress record class.
      Parameters:
      fileName - the value for the fileName record component
      bytesUploaded - the value for the bytesUploaded record component
      totalBytes - the value for the totalBytes record component
      elapsedMs - the value for the elapsedMs record component
  • Method Details

    • formattedPercentage

      public String formattedPercentage()
      Returns the upload percentage as a formatted string (e.g., "42.5%"). 以格式化字符串形式返回上传百分比(例如"42.5%")。
      Returns:
      formatted percentage string - 格式化的百分比字符串
    • throughputBytesPerSec

      public double throughputBytesPerSec()
      Returns the current upload throughput in bytes per second. Returns 0 if no time has elapsed. 以字节每秒返回当前上传吞吐量。如果没有经过时间则返回 0。
      Returns:
      throughput in bytes per second - 每秒字节数吞吐量
    • percentage

      public double percentage()
      Returns the upload percentage as a double (0.0 to 100.0). 以双精度浮点数(0.0 到 100.0)返回上传百分比。
      Returns:
      percentage - 百分比
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • fileName

      public String fileName()
      Returns the value of the fileName record component.
      Returns:
      the value of the fileName record component
    • bytesUploaded

      public long bytesUploaded()
      Returns the value of the bytesUploaded record component.
      Returns:
      the value of the bytesUploaded record component
    • totalBytes

      public long totalBytes()
      Returns the value of the totalBytes record component.
      Returns:
      the value of the totalBytes record component
    • elapsedMs

      public long elapsedMs()
      Returns the value of the elapsedMs record component.
      Returns:
      the value of the elapsedMs record component