public static String formatBytes(long bytes)
    {
        if (Long.MAX_VALUE == bytes)
        {
            return "\u221e B ";
        }

        String unit = "B ";
        double value = Math.abs(bytes);

        if (value > 1024)
        {
            value /= 1024;
            unit = "KB";
        }

        if (value > 1024)
        {
            value /= 1024;
            unit = "MB";
        }

        if (value > 1024)
        {
            value /= 1024;
            unit = "GB";
        }

        if (value > 1024)
        {
            value /= 1024;
            unit = "TB";
        }

        if (value > 1024)
        {
            value /= 1024;
            unit = "PB";
        }

        if (value > 1024)
        {
            value /= 1024;
            unit = "EB"; // the Enterprise might still use it.
        }

        String result = String.format("%,.1f %s", value, unit);

        if (bytes < 0)
        {
            result = "-" + result;
        }

        return result;
    }