Package com.couchbase.client.core.util
Class StorageSize
java.lang.Object
com.couchbase.client.core.util.StorageSize
A size measured in bytes, kibibytes, mebibytes, etc.
Create an instance using one of the "of" factory methods,
or from a string using parse(String)
.
-
Method Summary
Modifier and TypeMethodDescriptionlong
bytes()
Returns the storage size in bytes.int
Returns the storage size in bytes.boolean
format()
int
hashCode()
static StorageSize
ofBytes
(long value) static StorageSize
ofGibibytes
(long value) static StorageSize
ofKibibytes
(long value) static StorageSize
ofMebibytes
(long value) static StorageSize
ofPebibytes
(long value) static StorageSize
ofTebibytes
(long value) static StorageSize
Creates a new instance from its string representation: a whole number followed by a unit, optionally separated by whitespace.toString()
-
Method Details
-
parse
Creates a new instance from its string representation: a whole number followed by a unit, optionally separated by whitespace. Recognized units: B, KiB, MiB, GiB, TiB, PiB.Examples:
- "128B" or "128 B" -> 128 bytes
- "512KiB" or "512 KiB" -> 512 kibibytes
- "64MiB" or "64 MiB" -> 64 mebibytes
- etc.
- Throws:
IllegalArgumentException
- if the given string could not be parsed
-
ofBytes
- Throws:
IllegalArgumentException
- if value is negative
-
ofKibibytes
- Throws:
IllegalArgumentException
- if value is negative, or the size is greater thanLong.MAX_VALUE
bytes (~8191 PiB)
-
ofMebibytes
- Throws:
IllegalArgumentException
- if value is negative, or the size is greater thanLong.MAX_VALUE
bytes (~8191 PiB)
-
ofGibibytes
- Throws:
IllegalArgumentException
- if value is negative, or the size is greater thanLong.MAX_VALUE
bytes (~8191 PiB)
-
ofTebibytes
- Throws:
IllegalArgumentException
- if value is negative, or the size is greater thanLong.MAX_VALUE
bytes (~8191 PiB)
-
ofPebibytes
- Throws:
IllegalArgumentException
- if value is negative, or the size is greater thanLong.MAX_VALUE
bytes (~8191 PiB)
-
bytes
public long bytes()Returns the storage size in bytes. -
bytesAsInt
public int bytesAsInt()Returns the storage size in bytes.- Throws:
IllegalArgumentException
- if this size is >= 2 GiB
-
requireInt
-
format
-
toString
-
equals
-
hashCode
public int hashCode()
-