Package org.nuxeo.common.utils
Record Class ByteSize
java.lang.Object
java.lang.Record
org.nuxeo.common.utils.ByteSize
- Since:
- 2025.11
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final recordstatic enumUnits of byte size. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongbytes()Returns the value of thebytesrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static ByteSizeofBytes(long bytes) static ByteSizeofGibibytes(long gibibytes) static ByteSizeofKibibytes(long kibibytes) static ByteSizeofMebibytes(long mebibytes) static ByteSizeofPebibytes(long pebibytes) static ByteSizeofTebibytes(long tebibytes) static ByteSizeObtains aByteSizefrom a text string such as_g,_G,_GBor_GiB, with the following supported units:b,k,m,g,t,p.longtoBytes()longlonglonglongtoString()Returns theByteSizeformatted with the bigger unit it can fit into, meaning for example:long
-
Field Details
-
BYTE_SIZE_SIMPLE_FORMAT
-
-
Constructor Details
-
ByteSize
public ByteSize(long bytes) Creates an instance of aByteSizerecord class.- Parameters:
bytes- the value for thebytesrecord component
-
-
Method Details
-
ofBytes
-
ofKibibytes
-
ofMebibytes
-
ofGibibytes
-
ofTebibytes
-
ofPebibytes
-
parse
Obtains aByteSizefrom a text string such as_g,_G,_GBor_GiB, with the following supported units:b,k,m,g,t,p.A string without unit is parsed with the
bunit.- Throws:
NumberFormatException- if the text cannot be parsed to a byte size
-
toBytes
public long toBytes() -
toKibibytes
public long toKibibytes() -
toMebibytes
public long toMebibytes() -
toGibibytes
public long toGibibytes() -
toTebibytes
public long toTebibytes() -
toPebibytes
public long toPebibytes() -
toString
Returns theByteSizeformatted with the bigger unit it can fit into, meaning for example:System.out.println(ByteSize.ofGibibytes(1).toString()); // 1GiB System.out.println(ByteSize.ofMebibytes(1024).toString()); // 1GiB System.out.println(ByteSize.ofMebibytes(1025).toString()); // 1025MiB -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
bytes
public long bytes()Returns the value of thebytesrecord component.- Returns:
- the value of the
bytesrecord component
-