Java Size getSizeAll(final long bytes)

Here you can find the source of getSizeAll(final long bytes)

Description

get Size All

License

Open Source License

Declaration

public static String getSizeAll(final long bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    public static String getSizeAll(final long bytes) {
        return humanReadableByteCount(bytes, true) + " " + humanReadableByteCount(bytes, false) + " "
                + formatNumber(bytes) + " B";
    }//from ww w. j  ava 2  s .  c  o m

    public static String humanReadableByteCount(final long bytes) {
        return humanReadableByteCount(bytes, true);
    }

    private static String humanReadableByteCount(final long bytes, final boolean si) {
        final int unit = si ? 1000 : 1024;
        if (bytes < unit) {
            return bytes + " B";
        }

        final int exp = (int) (Math.log(bytes) / Math.log(unit));

        final String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");

        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }

    public static String formatNumber(final long val) {
        return NumberFormat.getNumberInstance(Locale.US).format(val);
    }
}

Related

  1. getFormatSize(long size)
  2. getFormattedSize(long size)
  3. getReadableByteSize(long size)
  4. getReadableSize(long size)
  5. getSize(long octets)
  6. getSizeFormat()
  7. getSizeInKB(String size)
  8. getSizeString(long bytes)
  9. getSizeString(long number, Locale locale)