Package io.dropwizard.util
Class DataSize
java.lang.Object
io.dropwizard.util.DataSize
- All Implemented Interfaces:
Serializable,Comparable<DataSize>
A data size with SI or IEC prefix, such as "128KB" or "5 Gibibytes".
This class models a size in terms of bytes and is immutable and thread-safe.
- Since:
- 2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DataSizebytes(long count) Constructs a newDataSizeobject representing the specified amount of bytes.intbooleanlongGets the quantity of the currentDataSizeobject.getUnit()Returns thedata size unitof the currentDataSizeobject.static DataSizegibibytes(long count) Constructs a newDataSizeobject representing the specified amount of gibibytes.static DataSizegigabytes(long count) Constructs a newDataSizeobject representing the specified amount of gigabytes.inthashCode()static DataSizekibibytes(long count) Constructs a newDataSizeobject representing the specified amount of kibibytes.static DataSizekilobytes(long count) Constructs a newDataSizeobject representing the specified amount of kilobytes.static DataSizemebibytes(long count) Constructs a newDataSizeobject representing the specified amount of mebibytes.static DataSizemegabytes(long count) Constructs a newDataSizeobject representing the specified amount of megabytes.static DataSizeparse(CharSequence size) Parses a givenCharSequenceto aDataSizeobject.static DataSizeparse(CharSequence size, DataSizeUnit defaultUnit) Parses a givenCharSequenceto aDataSizeobject.static DataSizepebibytes(long count) Constructs a newDataSizeobject representing the specified amount of pebibytes.static DataSizepetabytes(long count) Constructs a newDataSizeobject representing the specified amount of petabytes.static DataSizetebibytes(long count) Constructs a newDataSizeobject representing the specified amount of tebibytes.static DataSizeterabytes(long count) Constructs a newDataSizeobject representing the specified amount of terabytes.longtoBytes()Returns the quantity of the currentDataSizeobject in bytes.longReturns the quantity of the currentDataSizeobject in gibibytes.longReturns the quantity of the currentDataSizeobject in gigabytes.longReturns the quantity of the currentDataSizeobject in kibibytes.longReturns the quantity of the currentDataSizeobject in kilobytes.longReturns the quantity of the currentDataSizeobject in mebibytes.longReturns the quantity of the currentDataSizeobject in megabytes.longReturns the quantity of the currentDataSizeobject in pebibytes.longReturns the quantity of the currentDataSizeobject in petabytes.toString()longReturns the quantity of the currentDataSizeobject in gebibytes.longReturns the quantity of the currentDataSizeobject in terabytes.
-
Method Details
-
bytes
Constructs a newDataSizeobject representing the specified amount of bytes.- Parameters:
count- the amount of bytes- Returns:
- the newly created
DataSizeobject
-
kilobytes
Constructs a newDataSizeobject representing the specified amount of kilobytes.- Parameters:
count- the amount of kilobytes- Returns:
- the newly created
DataSizeobject
-
megabytes
Constructs a newDataSizeobject representing the specified amount of megabytes.- Parameters:
count- the amount of megabytes- Returns:
- the newly created
DataSizeobject
-
gigabytes
Constructs a newDataSizeobject representing the specified amount of gigabytes.- Parameters:
count- the amount of gigabytes- Returns:
- the newly created
DataSizeobject
-
terabytes
Constructs a newDataSizeobject representing the specified amount of terabytes.- Parameters:
count- the amount of terabytes- Returns:
- the newly created
DataSizeobject
-
petabytes
Constructs a newDataSizeobject representing the specified amount of petabytes.- Parameters:
count- the amount of petabytes- Returns:
- the newly created
DataSizeobject
-
kibibytes
Constructs a newDataSizeobject representing the specified amount of kibibytes.- Parameters:
count- the amount of kibibytes- Returns:
- the newly created
DataSizeobject
-
mebibytes
Constructs a newDataSizeobject representing the specified amount of mebibytes.- Parameters:
count- the amount of mebibytes- Returns:
- the newly created
DataSizeobject
-
gibibytes
Constructs a newDataSizeobject representing the specified amount of gibibytes.- Parameters:
count- the amount of gibibytes- Returns:
- the newly created
DataSizeobject
-
tebibytes
Constructs a newDataSizeobject representing the specified amount of tebibytes.- Parameters:
count- the amount of tebibytes- Returns:
- the newly created
DataSizeobject
-
pebibytes
Constructs a newDataSizeobject representing the specified amount of pebibytes.- Parameters:
count- the amount of pebibytes- Returns:
- the newly created
DataSizeobject
-
parse
Parses a givenCharSequenceto aDataSizeobject. If no unit is provided by the input sequence, a default unit ofDataSizeUnit.BYTESis used. -
parse
Parses a givenCharSequenceto aDataSizeobject. If no unit is provided by the input sequence, the default unit parameter is used.- Parameters:
size- the string representation of theDataSizeto parsedefaultUnit- the fallback default unit to use for the newly createdDataSize- Returns:
- a valid new
DataSizeobject representing the parsed string - Throws:
IllegalArgumentException- if the input sequence cannot be parsed correctly
-
getQuantity
public long getQuantity()Gets the quantity of the currentDataSizeobject.- Returns:
- the quantity of the current data size
-
getUnit
Returns thedata size unitof the currentDataSizeobject.- Returns:
- the unit of the current data size
-
toBytes
public long toBytes()Returns the quantity of the currentDataSizeobject in bytes.- Returns:
- the converted quantity
-
toKilobytes
public long toKilobytes()Returns the quantity of the currentDataSizeobject in kilobytes.- Returns:
- the converted quantity
-
toMegabytes
public long toMegabytes()Returns the quantity of the currentDataSizeobject in megabytes.- Returns:
- the converted quantity
-
toGigabytes
public long toGigabytes()Returns the quantity of the currentDataSizeobject in gigabytes.- Returns:
- the converted quantity
-
toTerabytes
public long toTerabytes()Returns the quantity of the currentDataSizeobject in terabytes.- Returns:
- the converted quantity
-
toPetabytes
public long toPetabytes()Returns the quantity of the currentDataSizeobject in petabytes.- Returns:
- the converted quantity
-
toKibibytes
public long toKibibytes()Returns the quantity of the currentDataSizeobject in kibibytes.- Returns:
- the converted quantity
-
toMebibytes
public long toMebibytes()Returns the quantity of the currentDataSizeobject in mebibytes.- Returns:
- the converted quantity
-
toGibibytes
public long toGibibytes()Returns the quantity of the currentDataSizeobject in gibibytes.- Returns:
- the converted quantity
-
toTebibytes
public long toTebibytes()Returns the quantity of the currentDataSizeobject in gebibytes.- Returns:
- the converted quantity
-
toPebibytes
public long toPebibytes()Returns the quantity of the currentDataSizeobject in pebibytes.- Returns:
- the converted quantity
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<DataSize>
-