public static String formatBytes(Long bytes, Locale locale) {
        if (bytes == null) {
            return "";
        }

        if (bytes == 0) {
            return "N/A";
        }

        String[] sizes = new String[] {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
        int i = (int) Math.floor(Math.log(bytes) / Math.log(1024));
        if (i == 0) {
            return bytes + " " + sizes[i];
        }
        else {
            DecimalFormat decimalFormat = new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(locale));
            return decimalFormat.format((bytes / Math.pow(1024, i))) + " " + sizes[i];
        }
    }
Formats the given data size in a more human-friendly format, e.g., `1.5 MB` etc.
@param bytes File size in bytes to format
@param locale The locale to use for number formatting
@return The given file size, formatted in a more human-friendly format. Returns empty string if bytes is null,
        or "N/A" if bytes is 0.
primefaces/src/main/java/org/primefaces/util/FileUploadUtils.java