Record Class ByteSize

java.lang.Object
java.lang.Record
org.nuxeo.common.utils.ByteSize

public record ByteSize(long bytes) extends Record
Since:
2025.11
  • Field Details

    • BYTE_SIZE_SIMPLE_FORMAT

      public static final Pattern BYTE_SIZE_SIMPLE_FORMAT
  • Constructor Details

    • ByteSize

      public ByteSize(long bytes)
      Creates an instance of a ByteSize record class.
      Parameters:
      bytes - the value for the bytes record component
  • Method Details

    • ofBytes

      public static ByteSize ofBytes(long bytes)
    • ofKibibytes

      public static ByteSize ofKibibytes(long kibibytes)
    • ofMebibytes

      public static ByteSize ofMebibytes(long mebibytes)
    • ofGibibytes

      public static ByteSize ofGibibytes(long gibibytes)
    • ofTebibytes

      public static ByteSize ofTebibytes(long tebibytes)
    • ofPebibytes

      public static ByteSize ofPebibytes(long pebibytes)
    • parse

      public static ByteSize parse(String value)
      Obtains a ByteSize from a text string such as _g, _G, _GB or _GiB, with the following supported units: b, k, m, g, t, p.

      A string without unit is parsed with the b unit.

      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

      public String toString()
      Returns the ByteSize formatted 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
       
       
      Specified by:
      toString in class Record
      Returns:
      the ByteSize formatted with the bigger unit it can fit into
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • bytes

      public long bytes()
      Returns the value of the bytes record component.
      Returns:
      the value of the bytes record component