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 Summary
ConstructorsConstructorDescriptionUploadProgress(String fileName, long bytesUploaded, long totalBytes, long elapsedMs) Creates an instance of aUploadProgressrecord class. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of thebytesUploadedrecord component.longReturns the value of theelapsedMsrecord component.final booleanIndicates whether some other object is "equal to" this one.fileName()Returns the value of thefileNamerecord component.Returns the upload percentage as a formatted string (e.g., "42.5%").final inthashCode()Returns a hash code value for this object.doubleReturns the upload percentage as a double (0.0 to 100.0).doubleReturns the current upload throughput in bytes per second.toString()Returns a string representation of this record class.longReturns the value of thetotalBytesrecord component.
-
Constructor Details
-
UploadProgress
Creates an instance of aUploadProgressrecord class.- Parameters:
fileName- the value for thefileNamerecord componentbytesUploaded- the value for thebytesUploadedrecord componenttotalBytes- the value for thetotalBytesrecord componentelapsedMs- the value for theelapsedMsrecord component
-
-
Method Details
-
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
fileName
-
bytesUploaded
public long bytesUploaded()Returns the value of thebytesUploadedrecord component.- Returns:
- the value of the
bytesUploadedrecord component
-
totalBytes
public long totalBytes()Returns the value of thetotalBytesrecord component.- Returns:
- the value of the
totalBytesrecord component
-
elapsedMs
-