Class FileSizeFormat

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class FileSizeFormat
    extends java.text.Format
    Converts a file size into a human-readable representation using binary prefixes (1KB = 1024 bytes). Only supports display and not parsing.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.text.Format

        java.text.Format.Field
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String[] ABBREVIATIONS
      The list of first letter abbreviations for each kilobyte power.
      static int KILOBYTE
      The binary value of a "kilo"byte.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuffer format​(java.lang.Object object, java.lang.StringBuffer stringBuffer, java.text.FieldPosition fieldPosition)
      Formats a file size.
      static FileSizeFormat getInstance()
      Returns a shared file size format instance.
      java.lang.Object parseObject​(java.lang.String arg0, java.text.ParsePosition arg1)
      This method is not supported.
      • Methods inherited from class java.text.Format

        clone, format, formatToCharacterIterator, parseObject
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • KILOBYTE

        public static final int KILOBYTE
        The binary value of a "kilo"byte.
        See Also:
        Constant Field Values
      • ABBREVIATIONS

        public static final java.lang.String[] ABBREVIATIONS
        The list of first letter abbreviations for each kilobyte power.
    • Method Detail

      • format

        public java.lang.StringBuffer format​(java.lang.Object object,
                                             java.lang.StringBuffer stringBuffer,
                                             java.text.FieldPosition fieldPosition)
        Formats a file size.
        Specified by:
        format in class java.text.Format
        Parameters:
        object - A Number containing the length of the file, in bytes. May be negative to indicate an unknown file size.
        stringBuffer - The string buffer to which the formatted output will be appended.
        fieldPosition - Not used.
        Returns:
        The original string buffer, with the formatted value appended.
      • parseObject

        @UnsupportedOperation
        public java.lang.Object parseObject​(java.lang.String arg0,
                                            java.text.ParsePosition arg1)
        This method is not supported.
        Specified by:
        parseObject in class java.text.Format
        Throws:
        java.lang.UnsupportedOperationException - always.
      • getInstance

        public static FileSizeFormat getInstance()
        Returns a shared file size format instance.
        Returns:
        A shared instance of this object.