Enum SizeUnit

java.lang.Object
java.lang.Enum<SizeUnit>
org.jboss.resteasy.spi.config.SizeUnit
All Implemented Interfaces:
Serializable, Comparable<SizeUnit>

public enum SizeUnit extends Enum<SizeUnit>
Represents units of size for things such as memory or files.
Author:
James R. Perkins
  • Enum Constant Details

    • BYTE

      public static final SizeUnit BYTE
    • KILOBYTE

      public static final SizeUnit KILOBYTE
    • MEGABYTE

      public static final SizeUnit MEGABYTE
    • GIGABYTE

      public static final SizeUnit GIGABYTE
    • TERABYTE

      public static final SizeUnit TERABYTE
    • PETABYTE

      public static final SizeUnit PETABYTE
    • EXABYTE

      public static final SizeUnit EXABYTE
  • Method Details

    • values

      public static SizeUnit[] 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

      public static SizeUnit valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • abbreviation

      public String abbreviation()
      Returns the abbreviation for the unit.
      Returns:
      the abbreviation for the unit
    • toBytes

      public long toBytes(long size)
      Converts the given size to bytes from this unit. For example SizeUnit.KILOBYTES.toBytes(1L) would return 1024.
      Parameters:
      size - the size to convert
      Returns:
      the size in bytes
    • convert

      public double convert(long size, SizeUnit unit)
      Converts the given size to the given unit to this unit.
      Parameters:
      size - the size to convert
      unit - the unit to convert the size to
      Returns:
      the converted units
    • toString

      public String toString(long size)
      Converts the size to a human-readable string format.

      For example SizeUnit.KILOBYTE.toString(1024L) would return "1 KB".

      Parameters:
      size - the size, in bytes
      Returns:
      a human-readable size
    • parent

      public SizeUnit parent()
      Returns the parent, previous, unit for this unit.
      Returns:
      the parent unit or null in the case of BYTE
    • toHumanReadable

      public static String toHumanReadable(long size)
      Converts the size, in bytes, to a human-readable form. For example 1024 bytes return "1 KB".
      Parameters:
      size - the size, in bytes, to convert
      Returns:
      a human-readable size