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 DataSize
bytes(long count)
Constructs a newDataSize
object representing the specified amount of bytes.int
compareTo(DataSize other)
boolean
equals(Object obj)
long
getQuantity()
Gets the quantity of the currentDataSize
object.DataSizeUnit
getUnit()
Returns thedata size unit
of the currentDataSize
object.static DataSize
gibibytes(long count)
Constructs a newDataSize
object representing the specified amount of gibibytes.static DataSize
gigabytes(long count)
Constructs a newDataSize
object representing the specified amount of gigabytes.int
hashCode()
static DataSize
kibibytes(long count)
Constructs a newDataSize
object representing the specified amount of kibibytes.static DataSize
kilobytes(long count)
Constructs a newDataSize
object representing the specified amount of kilobytes.static DataSize
mebibytes(long count)
Constructs a newDataSize
object representing the specified amount of mebibytes.static DataSize
megabytes(long count)
Constructs a newDataSize
object representing the specified amount of megabytes.static DataSize
parse(CharSequence size)
Parses a givenCharSequence
to aDataSize
object.static DataSize
parse(CharSequence size, DataSizeUnit defaultUnit)
Parses a givenCharSequence
to aDataSize
object.static DataSize
pebibytes(long count)
Constructs a newDataSize
object representing the specified amount of pebibytes.static DataSize
petabytes(long count)
Constructs a newDataSize
object representing the specified amount of petabytes.static DataSize
tebibytes(long count)
Constructs a newDataSize
object representing the specified amount of tebibytes.static DataSize
terabytes(long count)
Constructs a newDataSize
object representing the specified amount of terabytes.long
toBytes()
Returns the quantity of the currentDataSize
object in bytes.long
toGibibytes()
Returns the quantity of the currentDataSize
object in gibibytes.long
toGigabytes()
Returns the quantity of the currentDataSize
object in gigabytes.long
toKibibytes()
Returns the quantity of the currentDataSize
object in kibibytes.long
toKilobytes()
Returns the quantity of the currentDataSize
object in kilobytes.long
toMebibytes()
Returns the quantity of the currentDataSize
object in mebibytes.long
toMegabytes()
Returns the quantity of the currentDataSize
object in megabytes.long
toPebibytes()
Returns the quantity of the currentDataSize
object in pebibytes.long
toPetabytes()
Returns the quantity of the currentDataSize
object in petabytes.String
toString()
long
toTebibytes()
Returns the quantity of the currentDataSize
object in gebibytes.long
toTerabytes()
Returns the quantity of the currentDataSize
object in terabytes.
-
-
-
Method Detail
-
bytes
public static DataSize bytes(long count)
Constructs a newDataSize
object representing the specified amount of bytes.- Parameters:
count
- the amount of bytes- Returns:
- the newly created
DataSize
object
-
kilobytes
public static DataSize kilobytes(long count)
Constructs a newDataSize
object representing the specified amount of kilobytes.- Parameters:
count
- the amount of kilobytes- Returns:
- the newly created
DataSize
object
-
megabytes
public static DataSize megabytes(long count)
Constructs a newDataSize
object representing the specified amount of megabytes.- Parameters:
count
- the amount of megabytes- Returns:
- the newly created
DataSize
object
-
gigabytes
public static DataSize gigabytes(long count)
Constructs a newDataSize
object representing the specified amount of gigabytes.- Parameters:
count
- the amount of gigabytes- Returns:
- the newly created
DataSize
object
-
terabytes
public static DataSize terabytes(long count)
Constructs a newDataSize
object representing the specified amount of terabytes.- Parameters:
count
- the amount of terabytes- Returns:
- the newly created
DataSize
object
-
petabytes
public static DataSize petabytes(long count)
Constructs a newDataSize
object representing the specified amount of petabytes.- Parameters:
count
- the amount of petabytes- Returns:
- the newly created
DataSize
object
-
kibibytes
public static DataSize kibibytes(long count)
Constructs a newDataSize
object representing the specified amount of kibibytes.- Parameters:
count
- the amount of kibibytes- Returns:
- the newly created
DataSize
object
-
mebibytes
public static DataSize mebibytes(long count)
Constructs a newDataSize
object representing the specified amount of mebibytes.- Parameters:
count
- the amount of mebibytes- Returns:
- the newly created
DataSize
object
-
gibibytes
public static DataSize gibibytes(long count)
Constructs a newDataSize
object representing the specified amount of gibibytes.- Parameters:
count
- the amount of gibibytes- Returns:
- the newly created
DataSize
object
-
tebibytes
public static DataSize tebibytes(long count)
Constructs a newDataSize
object representing the specified amount of tebibytes.- Parameters:
count
- the amount of tebibytes- Returns:
- the newly created
DataSize
object
-
pebibytes
public static DataSize pebibytes(long count)
Constructs a newDataSize
object representing the specified amount of pebibytes.- Parameters:
count
- the amount of pebibytes- Returns:
- the newly created
DataSize
object
-
parse
public static DataSize parse(CharSequence size)
Parses a givenCharSequence
to aDataSize
object. If no unit is provided by the input sequence, a default unit ofDataSizeUnit.BYTES
is used.
-
parse
public static DataSize parse(CharSequence size, DataSizeUnit defaultUnit)
Parses a givenCharSequence
to aDataSize
object. If no unit is provided by the input sequence, the default unit parameter is used.- Parameters:
size
- the string representation of theDataSize
to parsedefaultUnit
- the fallback default unit to use for the newly createdDataSize
- Returns:
- a valid new
DataSize
object representing the parsed string - Throws:
IllegalArgumentException
- if the input sequence cannot be parsed correctly
-
getQuantity
public long getQuantity()
Gets the quantity of the currentDataSize
object.- Returns:
- the quantity of the current data size
-
getUnit
public DataSizeUnit getUnit()
Returns thedata size unit
of the currentDataSize
object.- Returns:
- the unit of the current data size
-
toBytes
public long toBytes()
Returns the quantity of the currentDataSize
object in bytes.- Returns:
- the converted quantity
-
toKilobytes
public long toKilobytes()
Returns the quantity of the currentDataSize
object in kilobytes.- Returns:
- the converted quantity
-
toMegabytes
public long toMegabytes()
Returns the quantity of the currentDataSize
object in megabytes.- Returns:
- the converted quantity
-
toGigabytes
public long toGigabytes()
Returns the quantity of the currentDataSize
object in gigabytes.- Returns:
- the converted quantity
-
toTerabytes
public long toTerabytes()
Returns the quantity of the currentDataSize
object in terabytes.- Returns:
- the converted quantity
-
toPetabytes
public long toPetabytes()
Returns the quantity of the currentDataSize
object in petabytes.- Returns:
- the converted quantity
-
toKibibytes
public long toKibibytes()
Returns the quantity of the currentDataSize
object in kibibytes.- Returns:
- the converted quantity
-
toMebibytes
public long toMebibytes()
Returns the quantity of the currentDataSize
object in mebibytes.- Returns:
- the converted quantity
-
toGibibytes
public long toGibibytes()
Returns the quantity of the currentDataSize
object in gibibytes.- Returns:
- the converted quantity
-
toTebibytes
public long toTebibytes()
Returns the quantity of the currentDataSize
object in gebibytes.- Returns:
- the converted quantity
-
toPebibytes
public long toPebibytes()
Returns the quantity of the currentDataSize
object in pebibytes.- Returns:
- the converted quantity
-
compareTo
public int compareTo(DataSize other)
- Specified by:
compareTo
in interfaceComparable<DataSize>
-
-