Class DownloadProgress

java.lang.Object
cloud.opencode.base.io.progress.DownloadProgress

public final class DownloadProgress extends Object
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 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

      public static DownloadProgress of(long totalBytes, long downloadedBytes, long speed)
      Creates a progress instance. 创建进度实例。
      Parameters:
      totalBytes - total bytes - 总字节数
      downloadedBytes - downloaded bytes - 已下载字节
      speed - speed in bytes/sec - 速度(字节/秒)
      Returns:
      the progress - 进度
    • completed

      public static DownloadProgress completed(long totalBytes)
      Creates a completed progress. 创建完成的进度。
      Parameters:
      totalBytes - total bytes - 总字节数
      Returns:
      the progress - 进度
    • unknown

      public static DownloadProgress unknown(long downloadedBytes, long speed)
      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

      public String formattedPercentage()
      Gets formatted percentage. 获取格式化的百分比。
      Returns:
      formatted percentage like "50.00%" - 格式化的百分比
    • formattedSpeed

      public String formattedSpeed()
      Gets formatted speed. 获取格式化的速度。
      Returns:
      formatted speed like "1.50 MB/s" - 格式化的速度
    • formattedTotalBytes

      public String formattedTotalBytes()
      Gets formatted total bytes. 获取格式化的总字节数。
      Returns:
      formatted total like "1.50 GB" - 格式化的总数
    • formattedDownloadedBytes

      public String formattedDownloadedBytes()
      Gets formatted downloaded bytes. 获取格式化的已下载字节。
      Returns:
      formatted downloaded like "500.00 MB" - 格式化的已下载
    • formattedRemainingTime

      public String formattedRemainingTime()
      Gets formatted remaining time. 获取格式化的剩余时间。
      Returns:
      formatted time like "2h 30m 15s" - 格式化的时间
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object