public class ByteSizeValue
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.math.BigDecimal |
KB_FACTOR
The factor 1024.
|
Modifier | Constructor and Description |
---|---|
protected |
ByteSizeValue()
Creates a new instance with the value: 0 bytes.
|
|
ByteSizeValue(java.math.BigDecimal numBytes)
Initialize the new instance with a value in bytes.
|
|
ByteSizeValue(java.math.BigDecimal value,
ByteSizeUnit unit)
Initialize the new instance with a value and unit.
|
|
ByteSizeValue(long numBytes)
Initialize the new instance with a value in bytes.
|
|
ByteSizeValue(long value,
ByteSizeUnit unit)
Initialize the new instance with a value and unit.
|
|
ByteSizeValue(java.lang.String strValue)
Initialize the new instance with a string that must contain digits,
an optional decimal point and
optionally followed by the prefix name of a unit (
ByteSizeUnit ). |
|
ByteSizeValue(java.lang.String strValue,
ByteSizeUnit defaultUnit)
Initialize the new instance with a string that must contain digits,
an optional decimal point and optionally followed by the prefix name of
a unit (
ByteSizeUnit ). |
Modifier and Type | Method and Description |
---|---|
java.math.BigDecimal |
asBytes()
Returns the value in BYTES.
|
java.math.BigDecimal |
asExaBytes()
Returns the value in EXA_BYTES.
|
java.math.BigDecimal |
asGigaBytes()
Returns the value in GIGA_BYTES.
|
java.math.BigDecimal |
asKiloBytes()
Returns the value in KILO_BYTES.
|
java.math.BigDecimal |
asMegaBytes()
Returns the value in MEGA_BYTES.
|
java.math.BigDecimal |
asPetaBytes()
Returns the value in PETA_BYTES.
|
java.math.BigDecimal |
asTeraBytes()
Returns the value in TERA_BYTES.
|
java.math.BigDecimal |
convertTo(ByteSizeUnit unit)
Returns the value converted to the specified unit.
|
boolean |
equals(java.lang.Object obj) |
protected ByteSizeUnit |
getCurrentUnit() |
long |
getSizeInBytes()
Returns the value in BYTES.
|
protected java.math.BigDecimal |
getValue() |
int |
hashCode() |
protected void |
parseAndInit(java.lang.String strValue,
ByteSizeUnit defaultUnit)
Parse the given string, taking any optional unit string at the end into account.
|
protected void |
setCurrentUnit(ByteSizeUnit currentUnit) |
protected void |
setValue(java.math.BigDecimal value) |
protected StringPair |
splitDigitsAndUnit(java.lang.String str) |
java.lang.String |
toString() |
public ByteSizeValue(java.math.BigDecimal numBytes)
public ByteSizeValue(long numBytes)
public ByteSizeValue(java.math.BigDecimal value, ByteSizeUnit unit)
public ByteSizeValue(long value, ByteSizeUnit unit)
public ByteSizeValue(java.lang.String strValue, ByteSizeUnit defaultUnit)
ByteSizeUnit
).
strValue
- The value with the optional unit definition (must not be null).defaultUnit
- The unit to be used if no explicit unit is defined in the string (must not be null).java.lang.NumberFormatException
- If the string does not contain a valid value or unit.public ByteSizeValue(java.lang.String strValue)
ByteSizeUnit
).
ByteSizeUnit.BYTES
) if no other unit is
explicitly set in the string.strValue
- The value with the optional unit definition (must not be null).java.lang.NumberFormatException
- If the string does not contain a valid value or unit.protected ByteSizeValue()
public long getSizeInBytes()
public java.math.BigDecimal asBytes()
public java.math.BigDecimal asKiloBytes()
public java.math.BigDecimal asMegaBytes()
public java.math.BigDecimal asGigaBytes()
public java.math.BigDecimal asTeraBytes()
public java.math.BigDecimal asPetaBytes()
public java.math.BigDecimal asExaBytes()
public java.math.BigDecimal convertTo(ByteSizeUnit unit)
unit
- The unit of the result value (must not be null).public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
protected void parseAndInit(java.lang.String strValue, ByteSizeUnit defaultUnit)
strValue
- The string to parse (may contain decimal point - except for unit "bytes").defaultUnit
- The unit to use if the string does not contain any explicit short name.java.lang.NumberFormatException
- If the string does not contain a valid decimal value or an invalid unit.protected StringPair splitDigitsAndUnit(java.lang.String str)
protected java.math.BigDecimal getValue()
protected void setValue(java.math.BigDecimal value)
protected ByteSizeUnit getCurrentUnit()
protected void setCurrentUnit(ByteSizeUnit currentUnit)