Class UnitFormatUtil


  • public final class UnitFormatUtil
    extends Object
    Utility class for formatting units
    • Field Detail

      • PROGRESSBAR_PERCENT

        public static final int PROGRESSBAR_PERCENT
        Display progressbar and only percent
        See Also:
        Constant Field Values
      • PROGRESSBAR_SIZE

        public static final int PROGRESSBAR_SIZE
        Display progressbar and only filesize
        See Also:
        Constant Field Values
      • NOPROGRESSBAR_PERCENT

        public static final int NOPROGRESSBAR_PERCENT
        Display no progressbar and only percent
        See Also:
        Constant Field Values
      • NOPROGRESSBAR_SIZE

        public static final int NOPROGRESSBAR_SIZE
        Display no progressbar and only filesize
        See Also:
        Constant Field Values
      • AUTO_CHANGE_SIZE

        public static final int AUTO_CHANGE_SIZE
        Takes automatically a suitable unit for displaying filesize
        See Also:
        Constant Field Values
      • ONLY_KIB

        public static final int ONLY_KIB
        Display filesize only as kibibytes
        See Also:
        Constant Field Values
      • ONLY_MIB

        public static final int ONLY_MIB
        Display filesize only as mebibytes
        See Also:
        Constant Field Values
      • ONLY_GIB

        public static final int ONLY_GIB
        Display filesize only as gibibytes
        See Also:
        Constant Field Values
      • ONLY_TIB

        public static final int ONLY_TIB
        Display filesize only as tebibytes
        See Also:
        Constant Field Values
    • Method Detail

      • getSizeString

        public static String getSizeString​(long size,
                                           int mode)
        Returns the bytes read in a suitable unit, or a specific unit, if the user defined that in the options
        Parameters:
        size - Number of bytes read
        mode -
        Returns:
        Progress-String
      • getPercentString

        public static String getPercentString​(long size,
                                              long max)
        Returns the progress as percent
        Parameters:
        size - Number of bytes read
        max - Filesize
        Returns:
        Percent-String
      • getBitrate

        public static double getBitrate​(long size,
                                        long max,
                                        long timeStarted,
                                        long timeNow)
        Calculates and returns the bitrate. If not possible -1 is returned
        Parameters:
        size - Number of bytes read
        max - Filesize
        timeStarted - Start-Time
        timeNow - Now
        Returns:
        Bitrate
      • getBitrateString

        public static String getBitrateString​(double rate)
        Returns a String with the download rate
        Parameters:
        rate - Bitrate
        Returns:
        String with the download rate