public enum HumanReadables extends Enum<HumanReadables>
The similar function in stackoverflow, linked: https://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java?r=SearchResults
Apache also provide similar function
FileUtils.byteCountToDisplaySize(long)
spring-core 5.x: org.springframework.util.unit.DataSize
| 限定符和类型 | 方法和说明 |
|---|---|
int |
base() |
String |
human(long size)
Returns a string of bytes count human-readable size
|
long |
parse(String size) |
long |
parse(String size,
boolean strict)
Parse the readable byte count, allowed suffix units: "1", "1 B", "1 MB", "1 MiB", "1 M"
|
long[] |
sizes() |
String[] |
units() |
static HumanReadables |
valueOf(String name)
返回带有指定名称的该类型的枚举常量。
|
static HumanReadables[] |
values()
按照声明该枚举类型的常量的顺序, 返回
包含这些常量的数组。
|
public static final HumanReadables SI
public static final HumanReadables BINARY
public static HumanReadables[] values()
for (HumanReadables c : HumanReadables.values()) System.out.println(c);
public static HumanReadables valueOf(String name)
name - 要返回的枚举常量的名称。IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量NullPointerException - 如果参数为空值public String human(long size)
size - the sizepublic long parse(String size)
public long parse(String size, boolean strict)
size - the sizestrict - the strict, if BINARY then verify whether contains "i"public int base()
public String[] units()
public long[] sizes()
Copyright © 2023. All rights reserved.