Class DownloadProgress
java.lang.Object
cloud.opencode.base.io.progress.DownloadProgress
Download Progress - Download Progress Information
下载进度 - 下载进度信息
This class represents the current progress of a download operation, including bytes transferred, speed, and estimated time remaining.
此类表示下载操作的当前进度,包括已传输字节、速度和预计剩余时间。
Example | 示例:
DownloadProgress progress = DownloadProgress.of(1000000, 500000, 100000);
System.out.println(progress.formattedPercentage()); // "50.00%"
System.out.println(progress.formattedSpeed()); // "100.00 KB/s"
Features | 主要功能:
- Download progress tracking with bytes/speed/percentage - 下载进度跟踪(字节/速度/百分比)
- Formatted output for percentage and speed - 格式化输出百分比和速度
- Estimated remaining time calculation - 估算剩余时间
Usage Examples | 使用示例:
DownloadProgress progress = DownloadProgress.of(1000000, 500000, 100000);
System.out.println(progress.formattedPercentage()); // "50.00%"
System.out.println(progress.formattedSpeed()); // "100.00 KB/s"
Security | 安全性:
- Thread-safe: No, mutable fields - 线程安全: 否,可变字段
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDownloadProgress(long totalBytes, long downloadedBytes, double percentage, long speed, long remainingTime) Creates a download progress. -
Method Summary
Modifier and TypeMethodDescriptionstatic DownloadProgresscompleted(long totalBytes) Creates a completed progress.booleanGets formatted downloaded bytes.Gets formatted percentage.Gets formatted remaining time.Gets formatted speed.Gets formatted total bytes.longGets the downloaded bytes.doubleGets the completion percentage.longGets the remaining time.longgetSpeed()Gets the download speed.longGets the total bytes.inthashCode()booleanChecks if download is complete.booleanChecks if total size is known.static DownloadProgressof(long totalBytes, long downloadedBytes, long speed) Creates a progress instance.toString()static DownloadProgressunknown(long downloadedBytes, long speed) Creates an unknown progress.
-
Constructor Details
-
DownloadProgress
public DownloadProgress(long totalBytes, long downloadedBytes, double percentage, long speed, long remainingTime) Creates a download progress. 创建下载进度。- Parameters:
totalBytes- total bytes to download - 总字节数downloadedBytes- downloaded bytes - 已下载字节percentage- completion percentage - 完成百分比speed- download speed in bytes/sec - 下载速度(字节/秒)remainingTime- remaining time in seconds - 剩余时间(秒)
-
-
Method Details
-
of
Creates a progress instance. 创建进度实例。- Parameters:
totalBytes- total bytes - 总字节数downloadedBytes- downloaded bytes - 已下载字节speed- speed in bytes/sec - 速度(字节/秒)- Returns:
- the progress - 进度
-
completed
Creates a completed progress. 创建完成的进度。- Parameters:
totalBytes- total bytes - 总字节数- Returns:
- the progress - 进度
-
unknown
Creates an unknown progress. 创建未知的进度。- Parameters:
downloadedBytes- downloaded bytes - 已下载字节speed- speed in bytes/sec - 速度(字节/秒)- Returns:
- the progress - 进度
-
getTotalBytes
public long getTotalBytes()Gets the total bytes. 获取总字节数。- Returns:
- total bytes or -1 if unknown - 总字节数或 -1(如果未知)
-
getDownloadedBytes
public long getDownloadedBytes()Gets the downloaded bytes. 获取已下载字节。- Returns:
- downloaded bytes - 已下载字节
-
getPercentage
public double getPercentage()Gets the completion percentage. 获取完成百分比。- Returns:
- percentage (0-100) or -1 if unknown - 百分比(0-100)或 -1(如果未知)
-
getSpeed
public long getSpeed()Gets the download speed. 获取下载速度。- Returns:
- speed in bytes per second - 速度(字节/秒)
-
getRemainingTime
public long getRemainingTime()Gets the remaining time. 获取剩余时间。- Returns:
- remaining time in seconds or -1 if unknown - 剩余时间(秒)或 -1(如果未知)
-
isComplete
public boolean isComplete()Checks if download is complete. 检查下载是否完成。- Returns:
- true if complete - 如果完成返回 true
-
isTotalKnown
public boolean isTotalKnown()Checks if total size is known. 检查总大小是否已知。- Returns:
- true if known - 如果已知返回 true
-
formattedPercentage
Gets formatted percentage. 获取格式化的百分比。- Returns:
- formatted percentage like "50.00%" - 格式化的百分比
-
formattedSpeed
Gets formatted speed. 获取格式化的速度。- Returns:
- formatted speed like "1.50 MB/s" - 格式化的速度
-
formattedTotalBytes
Gets formatted total bytes. 获取格式化的总字节数。- Returns:
- formatted total like "1.50 GB" - 格式化的总数
-
formattedDownloadedBytes
Gets formatted downloaded bytes. 获取格式化的已下载字节。- Returns:
- formatted downloaded like "500.00 MB" - 格式化的已下载
-
formattedRemainingTime
Gets formatted remaining time. 获取格式化的剩余时间。- Returns:
- formatted time like "2h 30m 15s" - 格式化的时间
-
equals
-
hashCode
-
toString
-