public static String bytesToString(long size) {
        long TB = 1L << 40;
        long GB = 1L << 30;
        long MB = 1L << 20;
        long KB = 1L << 10;

        double value;
        String unit;
        if (size >= 2 * TB) {
            value = (double) size / TB;
            unit = "TB";
        } else if (size >= 2 * GB) {
            value = (double) size / GB;
            unit = "GB";
        } else if (size >= 2 * MB) {
            value = (double) size / MB;
            unit = "MB";
        } else if (size >= 2 * KB) {
            value = (double) size / KB;
            unit = "KB";
        } else {
            value = (double) size;
            unit = "B";
        }
        return String.format("%.1f %s", value, unit);
    }
Convert a quantity in bytes to a human-readable string such as "4.0 MB".
indexr-query-opt/src/main/java/org/apache/spark/util/Utils.java