类 DataSize
java.lang.Object
cn.taketoday.util.DataSize
- 所有已实现的接口:
Serializable,Comparable<DataSize>
A data size, such as '12MB'.
This class models data size in terms of bytes and is immutable and thread-safe.
The terms and units used in this class are based on
binary prefixes
indicating multiplication by powers of 2. Consult the following table and
the Javadoc for DataUnit for details.
| Term | Data Size | Size in Bytes |
|---|---|---|
| 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 |
-
字段概要
字段修饰符和类型字段说明static final longBytes per Gigabyte.static final longBytes per Kilobyte.static final longBytes per Megabyte.static final longBytes per Terabyte. -
方法概要
修饰符和类型方法说明intbooleaninthashCode()booleanChecks if this size is negative, excluding zero.static DataSizestatic DataSizeofBytes(long bytes) Obtain aDataSizerepresenting the specified number of bytes.static DataSizeofGigabytes(long gigabytes) Obtain aDataSizerepresenting the specified number of gigabytes.static DataSizeofKilobytes(long kilobytes) Obtain aDataSizerepresenting the specified number of kilobytes.static DataSizeofMegabytes(long megabytes) Obtain aDataSizerepresenting the specified number of megabytes.static DataSizeofTerabytes(long terabytes) Obtain aDataSizerepresenting the specified number of terabytes.static DataSizeparse(CharSequence text) static DataSizeparse(CharSequence text, DataUnit defaultUnit) longtoBytes()Return the number of bytes in this instance.longReturn the number of gigabytes in this instance.longReturn the number of kilobytes in this instance.longReturn the number of megabytes in this instance.toString()longReturn the number of terabytes in this instance.
-
字段详细资料
-
BYTES_PER_KB
public static final long BYTES_PER_KBBytes per Kilobyte.- 另请参阅:
-
BYTES_PER_MB
public static final long BYTES_PER_MBBytes per Megabyte.- 另请参阅:
-
BYTES_PER_GB
public static final long BYTES_PER_GBBytes per Gigabyte.- 另请参阅:
-
BYTES_PER_TB
public static final long BYTES_PER_TBBytes per Terabyte.- 另请参阅:
-
-
方法详细资料
-
ofBytes
Obtain aDataSizerepresenting the specified number of bytes.- 参数:
bytes- the number of bytes, positive or negative- 返回:
- a
DataSize
-
ofKilobytes
Obtain aDataSizerepresenting the specified number of kilobytes.- 参数:
kilobytes- the number of kilobytes, positive or negative- 返回:
- a
DataSize
-
ofMegabytes
Obtain aDataSizerepresenting the specified number of megabytes.- 参数:
megabytes- the number of megabytes, positive or negative- 返回:
- a
DataSize
-
ofGigabytes
Obtain aDataSizerepresenting the specified number of gigabytes.- 参数:
gigabytes- the number of gigabytes, positive or negative- 返回:
- a
DataSize
-
ofTerabytes
Obtain aDataSizerepresenting the specified number of terabytes.- 参数:
terabytes- the number of terabytes, positive or negative- 返回:
- a
DataSize
-
of
- 参数:
amount- the amount of the size, measured in terms of the unit, positive or negative- 返回:
- a corresponding
DataSize
-
parse
Obtain aDataSizefrom a text string such as12MBusingDataUnit.BYTESif no unit is specified.Examples:
"12KB" -- parses as "12 kilobytes" "5MB" -- parses as "5 megabytes" "20" -- parses as "20 bytes"
- 参数:
text- the text to parse- 返回:
- the parsed
DataSize - 另请参阅:
-
parse
Obtain aDataSizefrom a text string such as12MBusing the specified defaultDataUnitif 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 the
defaultUnitisDataUnit.KILOBYTES)- 参数:
text- the text to parse- 返回:
- the parsed
DataSize
-
isNegative
public boolean isNegative()Checks if this size is negative, excluding zero.- 返回:
- true if this size has a size less than zero bytes
-
toBytes
public long toBytes()Return the number of bytes in this instance.- 返回:
- the number of bytes
-
toKilobytes
public long toKilobytes()Return the number of kilobytes in this instance.- 返回:
- the number of kilobytes
-
toMegabytes
public long toMegabytes()Return the number of megabytes in this instance.- 返回:
- the number of megabytes
-
toGigabytes
public long toGigabytes()Return the number of gigabytes in this instance.- 返回:
- the number of gigabytes
-
toTerabytes
public long toTerabytes()Return the number of terabytes in this instance.- 返回:
- the number of terabytes
-
compareTo
- 指定者:
compareTo在接口中Comparable<DataSize>
-
toString
-
equals
-
hashCode
public int hashCode()
-