@Override
    public StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos) {
        if (obj instanceof Long) {
            long numBytes = (Long) obj;
            if (numBytes < 1024 * 1024) {
                DecimalFormat formatter = new DecimalFormat("#,##0.0");
                buf.append(formatter.format((double)numBytes / 1024.0)).append(" K");
            }
            else {
                DecimalFormat formatter = new DecimalFormat("#,##0.0");
                buf.append(formatter.format((double)numBytes / (1024.0 * 1024.0))).append(" MB");
            }
        }
        return buf;
    }
Format the given object (must be a Long).

@param obj assumed to be the number of bytes as a Long.
@param buf the StringBuffer to append to.
@param pos the field position
@return A formatted string representing the given bytes in more human-readable form.
xmppserver/src/main/java/org/jivesoftware/util/ByteFormat.java