Record Class DiskInfo

java.lang.Object
java.lang.Record
cloud.opencode.base.core.system.DiskInfo
Record Components:
name - file store name - 文件存储名称
type - file store type (e.g. "ext4", "apfs", "ntfs") - 文件存储类型
totalSpace - total space in bytes - 总空间(字节)
usableSpace - usable space in bytes - 可用空间(字节)
unallocatedSpace - unallocated space in bytes - 未分配空间(字节)
readOnly - whether the file store is read-only - 是否只读

public record DiskInfo(String name, String type, long totalSpace, long usableSpace, long unallocatedSpace, boolean readOnly) extends Record
Immutable snapshot of disk/file-store information. 磁盘/文件存储信息的不可变快照。

Captures capacity and usage metrics for a single FileStore at the time of creation.

捕获创建时单个 FileStore 的容量和使用指标。

Usage Examples | 使用示例:

List<DiskInfo> disks = SystemInfo.disks();
for (DiskInfo disk : disks) {
    System.out.println(disk.name() + ": " + disk.usagePercent() + "% used");
}

DiskInfo current = SystemInfo.disk(Path.of("."));
System.out.println("Usable: " + current.usableDisplay());
Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo
See Also:
  • Constructor Details

    • DiskInfo

      public DiskInfo(String name, String type, long totalSpace, long usableSpace, long unallocatedSpace, boolean readOnly)
      Compact canonical constructor with validation. 带验证的紧凑规范构造器。
  • Method Details

    • usedSpace

      public long usedSpace()
      Returns the used space in bytes (total - unallocated). 返回已用空间(字节)(总量 - 未分配)。
      Returns:
      used space in bytes
    • usagePercent

      public double usagePercent()
      Returns the disk usage percentage (usedSpace / totalSpace * 100). 返回磁盘使用百分比(usedSpace / totalSpace * 100)。
      Returns:
      usage percentage in range [0.0, 100.0], or 0.0 if totalSpace is 0
    • totalDisplay

      public String totalDisplay()
      Returns a human-readable representation of total space. 返回总空间的可读表示。
      Returns:
      formatted string e.g. "500.0 GB"
    • usableDisplay

      public String usableDisplay()
      Returns a human-readable representation of usable space. 返回可用空间的可读表示。
      Returns:
      formatted string e.g. "250.0 GB"
    • toString

      public final 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.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • type

      public String type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • totalSpace

      public long totalSpace()
      Returns the value of the totalSpace record component.
      Returns:
      the value of the totalSpace record component
    • usableSpace

      public long usableSpace()
      Returns the value of the usableSpace record component.
      Returns:
      the value of the usableSpace record component
    • unallocatedSpace

      public long unallocatedSpace()
      Returns the value of the unallocatedSpace record component.
      Returns:
      the value of the unallocatedSpace record component
    • readOnly

      public boolean readOnly()
      Returns the value of the readOnly record component.
      Returns:
      the value of the readOnly record component