Class BytesFormat

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

    public class BytesFormat
    extends java.text.Format
    This class formats an instance of Bytes, Long, Integer, or Short based on the currently configured BytesDisplay preference.
    Since:
    1.5
    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 DETAILED_DECIMAL_FORMAT
      The default format string using for decimal byte values.
    • Constructor Summary

      Constructors 
      Constructor Description
      BytesFormat()
      Create an instance with default behavior.
      BytesFormat​(java.text.Format encapsulatedNumberFormat, java.text.Format encapsulatedDecimalFormat)
      Create an instance with the behavior that if the display preference is BytesDisplay.Bytes, always use encapsulatedNumberFormat; otherwise, use encapsulatedDecimalFormat if the value is more than 1KB.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuffer format​(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
      If obj is an instance of Bytes, long, integer or short, then consider the bytes display preference when formatting the value.
      static BytesFormat getInstance()
      Return a new instance of a BytesFormat with default options.
      java.lang.Object parseObject​(java.lang.String source, java.text.ParsePosition pos)
      Parses the input string according to the display mode.
      • Methods inherited from class java.text.Format

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

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

      • DETAILED_DECIMAL_FORMAT

        public static final java.lang.String DETAILED_DECIMAL_FORMAT
        The default format string using for decimal byte values.
        See Also:
        Constant Field Values
    • Constructor Detail

      • BytesFormat

        public BytesFormat()
        Create an instance with default behavior.
      • BytesFormat

        public BytesFormat​(java.text.Format encapsulatedNumberFormat,
                           java.text.Format encapsulatedDecimalFormat)
        Create an instance with the behavior that if the display preference is BytesDisplay.Bytes, always use encapsulatedNumberFormat; otherwise, use encapsulatedDecimalFormat if the value is more than 1KB.
        Parameters:
        encapsulatedNumberFormat - the format for small sizes
        encapsulatedDecimalFormat - the format for larger sizes
    • Method Detail

      • format

        public java.lang.StringBuffer format​(java.lang.Object obj,
                                             java.lang.StringBuffer toAppendTo,
                                             java.text.FieldPosition pos)
        If obj is an instance of Bytes, long, integer or short, then consider the bytes display preference when formatting the value. Otherwise, format obj using the default formatter.
        Specified by:
        format in class java.text.Format
      • parseObject

        public java.lang.Object parseObject​(java.lang.String source,
                                            java.text.ParsePosition pos)
        Parses the input string according to the display mode. Returns a Bytes object
        Specified by:
        parseObject in class java.text.Format
      • getInstance

        public static BytesFormat getInstance()
        Return a new instance of a BytesFormat with default options.
        Returns:
        a default BytesFormat