public class ByteSize
extends java.lang.Object
ByteSizeUnit.
This class supports converting to another ByteSizeUnit.| Constructor | Description |
|---|---|
ByteSize(double value,
ByteSizeUnit unit) |
Creates a byte size value from a
double value and a ByteSizeUnit. |
ByteSize(long bytes) |
Creates a byte size value from a
long value representing the number of bytes. |
ByteSize(long value,
ByteSizeUnit unit) |
Creates a byte size value from a
long value and a ByteSizeUnit. |
ByteSize(java.lang.String value,
ByteSizeUnit unit) |
Creates a byte size value from a
String value and a ByteSizeUnit. |
ByteSize(java.math.BigDecimal value,
ByteSizeUnit unit) |
Creates a byte size value from two parts, a value and a
ByteSizeUnit. |
| Modifier and Type | Method | Description |
|---|---|---|
ByteSize |
convertTo(ByteSizeUnit unit) |
Creates a new
ByteSize representing the same byte size but in a different unit. |
boolean |
equals(java.lang.Object o) |
|
java.math.BigInteger |
getBytes() |
Returns the number of bytes that this byte size represents after multiplying the unit factor with the value.
|
int |
getBytesAsInt() |
Returns the number of bytes that this byte size represents as an
int after multiplying the unit
factor with the value, throwing an exception if the result overflows an int. |
long |
getBytesAsLong() |
Returns the number of bytes that this byte size represents as a
long after multiplying the unit
factor with the value, throwing an exception if the result overflows a long. |
int |
hashCode() |
|
java.lang.String |
toString() |
public ByteSize(java.math.BigDecimal value,
ByteSizeUnit unit)
ByteSizeUnit.value - the value part of this byte size.unit - the unit part of this byte size.public ByteSize(long bytes)
long value representing the number of bytes.
The unit part of this byte size will be ByteSizeUnit.BYTES.bytes - the number of bytes this ByteSize instance should representpublic ByteSize(java.lang.String value,
ByteSizeUnit unit)
String value and a ByteSizeUnit.value - the value part of this byte sizeunit - the unit part of this byte sizepublic ByteSize(long value,
ByteSizeUnit unit)
long value and a ByteSizeUnit.value - the value part of this byte sizeunit - the unit part of this byte sizepublic ByteSize(double value,
ByteSizeUnit unit)
double value and a ByteSizeUnit.value - the value part of this byte sizeunit - the unit part of this byte sizepublic java.math.BigInteger getBytes()
RoundingMode.CEILING) to make sure that this method never gives values that
are too small.public long getBytesAsLong()
long after multiplying the unit
factor with the value, throwing an exception if the result overflows a long.java.lang.ArithmeticException - if the result overflows a longpublic int getBytesAsInt()
int after multiplying the unit
factor with the value, throwing an exception if the result overflows an int.java.lang.ArithmeticException - if the result overflows an intpublic ByteSize convertTo(ByteSizeUnit unit)
ByteSize representing the same byte size but in a different unit.
Scale of the value (number of decimal points) is handled automatically but if a non-terminating decimal expansion
occurs, an ArithmeticException is thrown.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.ObjectCopyright © 2012–2020 Luigi R. Viggiano. All rights reserved.