Package com.unboundid.util
Enum BinarySizeUnit
- All Implemented Interfaces:
Serializable,Comparable<BinarySizeUnit>,java.lang.constant.Constable
This enum defines a set of size units that can be used to represent data
sizes in varying units (bytes, kilobytes, megabytes, gigabytes, etc.). This
class uses binary-based values rather than decimal-based values, so each
unit is 1024 times larger than the previous (for example, one kilobyte is
interpreted as 1024 bytes rather than 1000 bytes).
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe size unit that represents bytes.The size unit that represents exabytes.The size unit that represents gigabytes.The size unit that represents kilobytes.The size unit that represents megabytes.The size unit that represents petabyte.The size unit that represents terabytes.The size unit that represents yottabytes.The size unit that represents zettabytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbytesToHumanReadableSize(long numBytes) Retrieves a string that represents a human-readable representation of the specified number of bytes.static StringbytesToHumanReadableSize(BigInteger numBytes) Retrieves a string that represents a human-readable representation of the specified number of bytes.static BinarySizeUnitRetrieves the binary size unit value that has the given name as either its singular name, plural name, or abbreviation, in a case-insensitive manner.fromBytes(long numBytes) Retrieves the number of instances of this unit represented by the specified number of bytes.fromBytes(BigInteger numBytes) Retrieves the number of instances of this unit represented by the specified number of bytes.Retrieves the abbreviation for this size unit.Retrieves the number of bytes per single instance of this size unit.Retrieves the plural name for this size unit.Retrieves the singular name for this size unit.toBytes(double value) Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.toBytes(long value) Retrieves the number of bytes in the specified number of instances of this size unit.toBytes(BigDecimal value) Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.toBytes(BigInteger value) Retrieves the number of bytes in the specified number of instances of this size unit.static BinarySizeUnitReturns the enum constant of this type with the specified name.static BinarySizeUnit[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
BYTES
The size unit that represents bytes. -
KILOBYTES
The size unit that represents kilobytes. Each kilobyte is 1024 bytes. -
MEGABYTES
The size unit that represents megabytes. Each megabyte is 1024 kilobytes. -
GIGABYTES
The size unit that represents gigabytes. Each gigabyte is 1024 megabytes. -
TERABYTES
The size unit that represents terabytes. Each terabyte is 1024 gigabytes. -
PETABYTES
The size unit that represents petabyte. Each petabyte is 1024 terabytes. -
EXABYTES
The size unit that represents exabytes. Each exabyte is 1024 petabytes. -
ZETTABYTES
The size unit that represents zettabytes. Each zettabyte is 1024 exabytes. -
YOTTABYTES
The size unit that represents yottabytes. Each yottabyte is 1024 zettabytes.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getNumBytesPerUnit
Retrieves the number of bytes per single instance of this size unit.- Returns:
- The number of bytes per single instance of this size unit.
-
getSingularName
Retrieves the singular name for this size unit.- Returns:
- The singular name for this size unit.
-
getPluralName
Retrieves the plural name for this size unit.- Returns:
- The plural name for this size unit.
-
getAbbreviation
Retrieves the abbreviation for this size unit.- Returns:
- The abbreviation for this size unit.
-
toBytes
Retrieves the number of bytes in the specified number of instances of this size unit.- Parameters:
value- The number of instances of this unit to convert to bytes.- Returns:
- The number of bytes in the specified number of instances of this size unit.
-
toBytes
Retrieves the number of bytes in the specified number of instances of this size unit.- Parameters:
value- The number of instances of this unit to convert to bytes. It must not benull.- Returns:
- The number of bytes in the specified number of instances of this size unit.
-
toBytes
Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.- Parameters:
value- The number of instances of this unit to convert to bytes.- Returns:
- The number of bytes in the specified number of instances of this size unit.
-
toBytes
Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.- Parameters:
value- The number of instances of this unit to convert to bytes. It must not benull.- Returns:
- The number of bytes in the specified number of instances of this size unit.
-
fromBytes
Retrieves the number of instances of this unit represented by the specified number of bytes.- Parameters:
numBytes- The number of bytes to use to make the determination.- Returns:
- The number of instances of this unit represented by the specified number of bytes.
-
fromBytes
Retrieves the number of instances of this unit represented by the specified number of bytes.- Parameters:
numBytes- The number of bytes to use to make the determination. It must not benull.- Returns:
- The number of instances of this unit represented by the specified number of bytes.
-
bytesToHumanReadableSize
Retrieves a string that represents a human-readable representation of the specified number of bytes. The string representation will be constructed in accordance with the following rules:- The string representation will use the abbreviation for the unit (e.g., "b" instead of "bytes", "KB" instead of kilobytes, etc.)
- If the provided value represents an exact multiple of the number of bytes for a given unit, then the string representation will be an integer followed by the abbreviation for the unit (e.g., a value of 123 will result in a string representation of "123b", a value of 524880 will result in a string representation of "5MB", a value of 7516192768 will result in a string representation of "7GB", etc.).
- If the provided value does not represent an exact multiple of the number of bytes for the given unit, then the string representation will use a floating-point number with two digits behind the decimal point. It will select the unit so that when possible, there will be between 1 and 3 digits before the decimal point (e.g., a value of 12345 will result in a string representation of "12.06KB", a value of 9876543210 will result in a string representation of "9.20GB", etc.).
- Parameters:
numBytes- The number of bytes to represent as a human-readable size. It must be greater than or equal to zero.- Returns:
- A string that represents a human-readable representation of the specified number of bytes.
-
bytesToHumanReadableSize
Retrieves a string that represents a human-readable representation of the specified number of bytes. The string representation will be constructed in accordance with the following rules:- The string representation will use the abbreviation for the unit (e.g., "B" instead of "bytes", "KB" instead of kilobytes, etc.)
- The string representation The string representation will use the abbreviation for the unit (e.g., "B" instead of "bytes", "KB" instead of kilobytes, etc.)
- If the provided value represents an exact multiple of the number of bytes for the selected unit, then the string representation will be an integer followed by the abbreviation for the unit (e.g., a value of 123 will result in a string representation of "123B", a value of 524880 will result in a string representation of "5MB", a value of 7516192768 will result in a string representation of "7GB", etc.).
- If the provided value does not represent an exact multiple of the number of bytes for the selected unit, then the string representation will use a floating-point number with two digits behind the decimal point (e.g., a value of 12345 will result in a string representation of "12.06KB", a value of 9876543210 will result in a string representation of "9.20GB", etc.).
- Parameters:
numBytes- The number of bytes to represent as a human-readable size. It must not benull, and it must represent a value that is greater than or equal to zero.- Returns:
- A string that represents a human-readable representation of the specified number of bytes.
-
forName
Retrieves the binary size unit value that has the given name as either its singular name, plural name, or abbreviation, in a case-insensitive manner.- Parameters:
name- The name for which to retrieve the binary size unit value. It must not benull.- Returns:
- The binary size unit value for the given name, or
nullif no value has a singular name, plural name, or abbreviation that matches the provided name in a case-insensitive manner.
-