org.jivesoftware.spark.util
Class ByteFormat

java.lang.Object
  extended by java.text.Format
      extended by org.jivesoftware.spark.util.ByteFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ByteFormat
extends java.text.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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
ByteFormat()
           
 
Method Summary
 java.lang.String format(long bytes)
          Formats a long which represent a number of bytes.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer buf, java.text.FieldPosition pos)
          Format the given object (must be a Long).
 java.lang.String formatKB(long kilobytes)
          Formats a long which represent a number of kilobytes.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          In this implementation, returns null always.
 
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
 

Constructor Detail

ByteFormat

public ByteFormat()
Method Detail

format

public java.lang.String format(long bytes)
Formats a long which represent a number of bytes.


formatKB

public java.lang.String formatKB(long kilobytes)
Formats a long which represent a number of kilobytes.


format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer buf,
                                     java.text.FieldPosition pos)
Format the given object (must be a Long).

Specified by:
format in class java.text.Format
Parameters:
obj - assumed to be the number of bytes as a Long.
buf - the StringBuffer to append to.
pos -
Returns:
A formatted string representing the given bytes in more human-readable form.

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition pos)
In this implementation, returns null always.

Specified by:
parseObject in class java.text.Format
Parameters:
source -
pos -
Returns:
returns null in this implementation.