Package io.dropwizard.util
Class DataSize
- java.lang.Object
-
- io.dropwizard.util.DataSize
-
- All Implemented Interfaces:
Serializable,Comparable<DataSize>
public class DataSize extends Object implements Comparable<DataSize>, Serializable
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:
DataSizeUnit, Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataSizebytes(long count)Constructs a newDataSizeobject representing the specified amount of bytes.intcompareTo(DataSize other)booleanequals(Object obj)longgetQuantity()Gets the quantity of the currentDataSizeobject.DataSizeUnitgetUnit()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.longtoGibibytes()Returns the quantity of the currentDataSizeobject in gibibytes.longtoGigabytes()Returns the quantity of the currentDataSizeobject in gigabytes.longtoKibibytes()Returns the quantity of the currentDataSizeobject in kibibytes.longtoKilobytes()Returns the quantity of the currentDataSizeobject in kilobytes.longtoMebibytes()Returns the quantity of the currentDataSizeobject in mebibytes.longtoMegabytes()Returns the quantity of the currentDataSizeobject in megabytes.longtoPebibytes()Returns the quantity of the currentDataSizeobject in pebibytes.longtoPetabytes()Returns the quantity of the currentDataSizeobject in petabytes.StringtoString()longtoTebibytes()Returns the quantity of the currentDataSizeobject in gebibytes.longtoTerabytes()Returns the quantity of the currentDataSizeobject in terabytes.
-
-
-
Method Detail
-
bytes
public static DataSize bytes(long count)
Constructs a newDataSizeobject representing the specified amount of bytes.- Parameters:
count- the amount of bytes- Returns:
- the newly created
DataSizeobject
-
kilobytes
public static DataSize kilobytes(long count)
Constructs a newDataSizeobject representing the specified amount of kilobytes.- Parameters:
count- the amount of kilobytes- Returns:
- the newly created
DataSizeobject
-
megabytes
public static DataSize megabytes(long count)
Constructs a newDataSizeobject representing the specified amount of megabytes.- Parameters:
count- the amount of megabytes- Returns:
- the newly created
DataSizeobject
-
gigabytes
public static DataSize gigabytes(long count)
Constructs a newDataSizeobject representing the specified amount of gigabytes.- Parameters:
count- the amount of gigabytes- Returns:
- the newly created
DataSizeobject
-
terabytes
public static DataSize terabytes(long count)
Constructs a newDataSizeobject representing the specified amount of terabytes.- Parameters:
count- the amount of terabytes- Returns:
- the newly created
DataSizeobject
-
petabytes
public static DataSize petabytes(long count)
Constructs a newDataSizeobject representing the specified amount of petabytes.- Parameters:
count- the amount of petabytes- Returns:
- the newly created
DataSizeobject
-
kibibytes
public static DataSize kibibytes(long count)
Constructs a newDataSizeobject representing the specified amount of kibibytes.- Parameters:
count- the amount of kibibytes- Returns:
- the newly created
DataSizeobject
-
mebibytes
public static DataSize mebibytes(long count)
Constructs a newDataSizeobject representing the specified amount of mebibytes.- Parameters:
count- the amount of mebibytes- Returns:
- the newly created
DataSizeobject
-
gibibytes
public static DataSize gibibytes(long count)
Constructs a newDataSizeobject representing the specified amount of gibibytes.- Parameters:
count- the amount of gibibytes- Returns:
- the newly created
DataSizeobject
-
tebibytes
public static DataSize tebibytes(long count)
Constructs a newDataSizeobject representing the specified amount of tebibytes.- Parameters:
count- the amount of tebibytes- Returns:
- the newly created
DataSizeobject
-
pebibytes
public static DataSize pebibytes(long count)
Constructs a newDataSizeobject representing the specified amount of pebibytes.- Parameters:
count- the amount of pebibytes- Returns:
- the newly created
DataSizeobject
-
parse
public static DataSize parse(CharSequence size)
Parses a givenCharSequenceto aDataSizeobject. If no unit is provided by the input sequence, a default unit ofDataSizeUnit.BYTESis used.
-
parse
public static DataSize parse(CharSequence size, DataSizeUnit defaultUnit)
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
public DataSizeUnit 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
-
compareTo
public int compareTo(DataSize other)
- Specified by:
compareToin interfaceComparable<DataSize>
-
-