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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.name()Returns the value of thenamerecord component.booleanreadOnly()Returns the value of thereadOnlyrecord component.final StringtoString()Returns a string representation of this record class.Returns a human-readable representation of total space.longReturns the value of thetotalSpacerecord component.type()Returns the value of thetyperecord component.longReturns the value of theunallocatedSpacerecord component.Returns a human-readable representation of usable space.longReturns the value of theusableSpacerecord component.doubleReturns the disk usage percentage (usedSpace / totalSpace * 100).longReturns the used space in bytes (total - unallocated).
-
Constructor Details
-
DiskInfo
-
-
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
Returns a human-readable representation of total space. 返回总空间的可读表示。- Returns:
- formatted string e.g. "500.0 GB"
-
usableDisplay
Returns a human-readable representation of usable space. 返回可用空间的可读表示。- Returns:
- formatted string e.g. "250.0 GB"
-
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. -
name
-
type
-
totalSpace
public long totalSpace()Returns the value of thetotalSpacerecord component.- Returns:
- the value of the
totalSpacerecord component
-
usableSpace
public long usableSpace()Returns the value of theusableSpacerecord component.- Returns:
- the value of the
usableSpacerecord component
-
unallocatedSpace
public long unallocatedSpace()Returns the value of theunallocatedSpacerecord component.- Returns:
- the value of the
unallocatedSpacerecord component
-
readOnly
-