- All Implemented Interfaces:
Serializable,Comparable<LongValue>
- Bytes.bytes(long)
- Bytes.kilobytes(long)
- Bytes.megabytes(long)
- Bytes.gigabytes(long)
- Bytes.terabytes(long)
or double precision floating point values like megabytes(3.2):
- Bytes.bytes(double)
- Bytes.kilobytes(double)
- Bytes.megabytes(double)
- Bytes.gigabytes(double)
- Bytes.terabytes(double)
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:
- kilobytes()
- megabytes()
- gigabytes()
- terabytes()
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:
- 37 (37 bytes)
- 2.3K (2.3 kilobytes)
- 2.5 kb (2.5 kilobytes)
- 4k (4 kilobytes)
- 35.2GB (35.2 gigabytes)
- 1024M (1024 megabytes)
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.
- Author:
- Jonathan Locke
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfinal longbytes()Gets the byte count represented by this value object.static Bytesbytes(double bytes) Instantiate immutable Bytes value object..static Bytesbytes(long bytes) Instantiate immutable Bytes value object..final doubleGets the byte count in gigabytes.static Bytesgigabytes(double gigabytes) Instantiate immutable Bytes value object..static Bytesgigabytes(long gigabytes) Instantiate immutable Bytes value object..booleangreaterThan(Bytes other) Compares thisByteswith anotherBytesinstance.final doubleGets the byte count in kilobytes.static Byteskilobytes(double kilobytes) Instantiate immutable Bytes value object..static Byteskilobytes(long kilobytes) Instantiate immutable Bytes value object..final doubleGets the byte count in megabytes.static Bytesmegabytes(double megabytes) Instantiate immutable Bytes value object..static Bytesmegabytes(long megabytes) Instantiate immutable Bytes value object..final doubleGets the byte count in terabytes.static Bytesterabytes(double terabytes) Instantiate immutable Bytes value object..static Bytesterabytes(long terabytes) Instantiate immutable Bytes value object..toString()Converts this byte count to a string using the default locale.Converts this byte count to a string using the given locale.static BytesConverts a string to a number of bytes.static BytesConverts a string to a number of bytes.Methods inherited from class org.apache.wicket.util.value.LongValue
compareTo, equals, greaterThan, greaterThan, greaterThanOrEqual, greaterThanOrEqual, hashCode, lessThan, lessThan, lessThanOrEqual, lessThanOrEqual, max, maxNullSafe, min
-
Field Details
-
MAX
Maximum bytes value
-
-
Method Details
-
bytes
Instantiate immutable Bytes value object..- Parameters:
bytes- Value to convert- Returns:
- Input as Bytes
-
kilobytes
Instantiate immutable Bytes value object..- Parameters:
kilobytes- Value to convert- Returns:
- Input as Bytes
-
megabytes
Instantiate immutable Bytes value object..- Parameters:
megabytes- Value to convert- Returns:
- Input as Bytes
-
gigabytes
Instantiate immutable Bytes value object..- Parameters:
gigabytes- Value to convert- Returns:
- Input as Bytes
-
terabytes
Instantiate immutable Bytes value object..- Parameters:
terabytes- Value to convert- Returns:
- Input as Bytes
-
bytes
Instantiate immutable Bytes value object..- Parameters:
bytes- Value to convert- Returns:
- Input as Bytes
-
kilobytes
Instantiate immutable Bytes value object..- Parameters:
kilobytes- Value to convert- Returns:
- Input as Bytes
-
megabytes
Instantiate immutable Bytes value object..- Parameters:
megabytes- Value to convert- Returns:
- Input as Bytes
-
gigabytes
Instantiate immutable Bytes value object..- Parameters:
gigabytes- Value to convert- Returns:
- Input as Bytes
-
terabytes
Instantiate immutable Bytes value object..- Parameters:
terabytes- Value to convert- Returns:
- Input as Bytes
-
bytes
Gets the byte count represented by this value object.- Returns:
- Byte count
-
kilobytes
Gets the byte count in kilobytes.- Returns:
- The value in kilobytes
-
megabytes
Gets the byte count in megabytes.- Returns:
- The value in megabytes
-
gigabytes
Gets the byte count in gigabytes.- Returns:
- The value in gigabytes
-
terabytes
Gets the byte count in terabytes.- Returns:
- The value in terabytes
-
valueOf
Converts a string to a number of bytes. Strings consist of a floating point value followed by K, M, G or T for kilobytes, megabytes, gigabytes or terabytes, respectively. The abbreviations KB, MB, GB and TB are also accepted. Matching is case insensitive.- Parameters:
string- The string to convertlocale- The Locale to be used for transformation- Returns:
- The Bytes value for the string
- Throws:
StringValueConversionException
-
valueOf
Converts a string to a number of bytes. Strings consist of a floating point value followed by K, M, G or T for kilobytes, megabytes, gigabytes or terabytes, respectively. The abbreviations KB, MB, GB and TB are also accepted. Matching is case insensitive.- Parameters:
string- The string to convert- Returns:
- The Bytes value for the string
- Throws:
StringValueConversionException
-
toString
Converts this byte count to a string using the default locale. -
toString
Converts this byte count to a string using the given locale.- Parameters:
locale- Locale to use for conversion- Returns:
- The string for this byte count
-
greaterThan
Compares thisByteswith anotherBytesinstance.- Parameters:
other- theBytesinstance to compare with- Returns:
trueif thisBytesis greater than the givenBytesinstance
-