public final class Bytes extends LongValue
or double precision floating point values like megabytes(3.2):
In the case of bytes(double), the value will be rounded off to the nearest integer byte count using Math.round().
The precise number of bytes in a Bytes object can be retrieved by calling bytes(). Approximate values for different units can be retrieved as double precision values using these methods:
Also, value objects can be constructed from strings, optionally using a Locale with valueOf(String) and valueOf(String,Locale). The string may contain a decimal or floating point number followed by optional whitespace followed by a unit (nothing for bytes, K for kilobyte, M for megabytes, G for gigabytes or T for terabytes) optionally followed by a B (for bytes). Any of these letters can be any case. So, examples of permissible string values are:
Note that if the Locale was not US, the values might substitute "," for "." as that is the custom in Euroland.
The toString() and toString(Locale) methods are smart enough to convert a given value object to the most appropriate units for the given value.
Modifier and Type | Method and Description |
---|---|
long |
bytes()
Gets the byte count represented by this value object.
|
static Bytes |
bytes(double bytes)
Instantiate immutable Bytes value object..
|
static Bytes |
bytes(long bytes)
Instantiate immutable Bytes value object..
|
double |
gigabytes()
Gets the byte count in gigabytes.
|
static Bytes |
gigabytes(double gigabytes)
Instantiate immutable Bytes value object..
|
static Bytes |
gigabytes(long gigabytes)
Instantiate immutable Bytes value object..
|
boolean |
greaterThan(Bytes other)
Compares this
Bytes with another Bytes instance. |
double |
kilobytes()
Gets the byte count in kilobytes.
|
static Bytes |
kilobytes(double kilobytes)
Instantiate immutable Bytes value object..
|
static Bytes |
kilobytes(long kilobytes)
Instantiate immutable Bytes value object..
|
double |
megabytes()
Gets the byte count in megabytes.
|
static Bytes |
megabytes(double megabytes)
Instantiate immutable Bytes value object..
|
static Bytes |
megabytes(long megabytes)
Instantiate immutable Bytes value object..
|
double |
terabytes()
Gets the byte count in terabytes.
|
static Bytes |
terabytes(double terabytes)
Instantiate immutable Bytes value object..
|
static Bytes |
terabytes(long terabytes)
Instantiate immutable Bytes value object..
|
String |
toString()
Converts this byte count to a string using the default locale.
|
String |
toString(Locale locale)
Converts this byte count to a string using the given locale.
|
static Bytes |
valueOf(String string)
Converts a string to a number of bytes.
|
static Bytes |
valueOf(String string,
Locale locale)
Converts a string to a number of bytes.
|
compareTo, equals, greaterThan, greaterThan, greaterThanOrEqual, greaterThanOrEqual, hashCode, lessThan, lessThan, lessThanOrEqual, lessThanOrEqual, max, maxNullSafe, min
public static final Bytes MAX
public static Bytes bytes(long bytes)
bytes
- Value to convertpublic static Bytes kilobytes(long kilobytes)
kilobytes
- Value to convertpublic static Bytes megabytes(long megabytes)
megabytes
- Value to convertpublic static Bytes gigabytes(long gigabytes)
gigabytes
- Value to convertpublic static Bytes terabytes(long terabytes)
terabytes
- Value to convertpublic static Bytes bytes(double bytes)
bytes
- Value to convertpublic static Bytes kilobytes(double kilobytes)
kilobytes
- Value to convertpublic static Bytes megabytes(double megabytes)
megabytes
- Value to convertpublic static Bytes gigabytes(double gigabytes)
gigabytes
- Value to convertpublic static Bytes terabytes(double terabytes)
terabytes
- Value to convertpublic final long bytes()
public final double kilobytes()
public final double megabytes()
public final double gigabytes()
public final double terabytes()
public static Bytes valueOf(String string, Locale locale) throws StringValueConversionException
string
- The string to convertlocale
- The Locale to be used for transformationStringValueConversionException
public static Bytes valueOf(String string) throws StringValueConversionException
string
- The string to convertStringValueConversionException
public String toString()
public String toString(Locale locale)
locale
- Locale to use for conversionpublic boolean greaterThan(Bytes other)
Bytes
with another Bytes
instance.other
- the Bytes
instance to compare withtrue
if this Bytes
is greater than the given
Bytes
instanceCopyright © 2006–2022 Apache Software Foundation. All rights reserved.