Class ByteFormat

  • All Implemented Interfaces:
    Serializable, Cloneable

    public class ByteFormat
    extends Format
    A formatter for formatting byte sizes. For example, formatting 12345 byes results in "12.1 K" and 1234567 results in "1.18 MB".
    Author:
    Bill Lynch
    See Also:
    Serialized Form
    • Constructor Detail

      • ByteFormat

        public ByteFormat()
    • Method Detail

      • format

        public String format​(long bytes)
        Formats a long which represent a number of bytes.
        Parameters:
        bytes - the number of bytes to format
        Returns:
        the formatted string
      • formatKB

        public String formatKB​(long kilobytes)
        Formats a long which represent a number of kilobytes.
        Parameters:
        kilobytes - the number of kilobytes to format
        Returns:
        the formatted string
      • format

        public StringBuffer format​(Object obj,
                                   StringBuffer buf,
                                   FieldPosition pos)
        Format the given object (must be a Long).
        Specified by:
        format in class Format
        Parameters:
        obj - assumed to be the number of bytes as a Long.
        buf - the StringBuffer to append to.
        pos - the field position
        Returns:
        A formatted string representing the given bytes in more human-readable form.
      • parseObject

        public Object parseObject​(String source,
                                  ParsePosition pos)
        In this implementation, returns null always.
        Specified by:
        parseObject in class Format
        Parameters:
        source - unused parameter
        pos - unused parameter
        Returns:
        returns null in this implementation.