public final class DataSize extends Object implements Comparable<DataSize>
此类来自于:Spring-framework
byte 1B 1 kilobyte 1KB 1,024 megabyte 1MB 1,048,576 gigabyte 1GB 1,073,741,824 terabyte 1TB 1,099,511,627,776
Modifier and Type | Method and Description |
---|---|
int |
compareTo(DataSize other) |
boolean |
equals(Object other) |
int |
hashCode() |
boolean |
isNegative()
是否为负数,不包括0
|
static DataSize |
of(BigDecimal amount,
DataUnit unit)
获得指定
DataUnit 对应的DataSize |
static DataSize |
of(long amount,
DataUnit unit)
获得指定
DataUnit 对应的DataSize |
static DataSize |
ofBytes(long bytes)
获得对应bytes的DataSize
|
static DataSize |
ofGigabytes(long gigabytes)
获得对应gigabytes的DataSize
|
static DataSize |
ofKilobytes(long kilobytes)
获得对应kilobytes的DataSize
|
static DataSize |
ofMegabytes(long megabytes)
获得对应megabytes的DataSize
|
static DataSize |
ofTerabytes(long terabytes)
获得对应terabytes的DataSize
|
static DataSize |
parse(CharSequence text)
获取指定数据大小文本对应的DataSize对象,如果无单位指定,默认获取
DataUnit.BYTES
例如:
"12KB" -- parses as "12 kilobytes"
"5MB" -- parses as "5 megabytes"
"20" -- parses as "20 bytes"
|
static DataSize |
parse(CharSequence text,
DataUnit defaultUnit)
Obtain a DataSize from a text string such as
12MB using
the specified default DataUnit if no unit is specified. |
long |
toBytes()
返回bytes大小
|
long |
toGigabytes()
返回GB大小
|
long |
toKilobytes()
返回KB大小
|
long |
toMegabytes()
返回MB大小
|
String |
toString() |
long |
toTerabytes()
返回TB大小
|
public static DataSize ofBytes(long bytes)
bytes
- bytes大小,可正可负public static DataSize ofKilobytes(long kilobytes)
kilobytes
- kilobytes大小,可正可负public static DataSize ofMegabytes(long megabytes)
megabytes
- megabytes大小,可正可负public static DataSize ofGigabytes(long gigabytes)
gigabytes
- gigabytes大小,可正可负public static DataSize ofTerabytes(long terabytes)
terabytes
- terabytes大小,可正可负public static DataSize of(long amount, DataUnit unit)
DataUnit
对应的DataSizeamount
- 大小unit
- 数据大小单位,null表示默认的BYTESpublic static DataSize of(BigDecimal amount, DataUnit unit)
DataUnit
对应的DataSizeamount
- 大小unit
- 数据大小单位,null表示默认的BYTESpublic static DataSize parse(CharSequence text)
DataUnit.BYTES
例如:
"12KB" -- parses as "12 kilobytes" "5MB" -- parses as "5 megabytes" "20" -- parses as "20 bytes"
text
- the text to parseparse(CharSequence, DataUnit)
public static DataSize parse(CharSequence text, DataUnit defaultUnit)
12MB
using
the specified default DataUnit
if no unit is specified.
The string starts with a number followed optionally by a unit matching one of the supported suffixes.
Examples:
"12KB" -- parses as "12 kilobytes" "5MB" -- parses as "5 megabytes" "20" -- parses as "20 kilobytes" (where thedefaultUnit
isDataUnit.KILOBYTES
)
text
- the text to parsedefaultUnit
- 默认的数据单位public boolean isNegative()
public long toBytes()
public long toKilobytes()
public long toMegabytes()
public long toGigabytes()
public long toTerabytes()
public int compareTo(DataSize other)
compareTo
in interface Comparable<DataSize>
Copyright © 2024. All rights reserved.