Class HumanReadableBytes


  • public class HumanReadableBytes
    extends Object
    • Constructor Detail

      • HumanReadableBytes

        public HumanReadableBytes​(String bytes)
      • HumanReadableBytes

        public HumanReadableBytes​(long bytes)
    • Method Detail

      • getBytes

        public long getBytes()
      • getBytesInInt

        public int getBytesInInt()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • parse

        public static long parse​(String number)
      • parse

        public static long parse​(String number,
                                 long nullValue)
        parse the case-insensitive string number, which is either:

        a number string

        or

        a number string with a suffix which indicates the unit the of number the unit must be one of following k - kilobyte = 1000 m - megabyte = 1,000,000 g - gigabyte = 1,000,000,000 t - terabyte = 1,000,000,000,000 p - petabyte = 1,000,000,000,000,000 Ki(B) - kilo binary byte = 1024 Mi(B) - mega binary byte = 1024*1204 Gi(B) - giga binary byte = 1024*1024*1024 Ti(B) - tera binary byte = 1024*1024*1024*1024 Pi(B) - peta binary byte = 1024*1024*1024*1024*1024

        Parameters:
        nullValue - to be returned when given number is null or empty
        Returns:
        nullValue if input is null or empty value of number
        Throws:
        IAE - if the input is invalid
      • format

        public static String format​(long bytes,
                                    long precision,
                                    HumanReadableBytes.UnitSystem unitSystem)
        Returns a human-readable string version of input value
        Parameters:
        bytes - input value. Negative value is also allowed
        precision - [0,3]
        unitSystem - which unit system is adopted to format the input value, see HumanReadableBytes.UnitSystem