Java Utililty Methods Memory Format

List of utility methods to do Memory Format

Description

The list of methods to do Memory Format are organized into topic(s).

Method

StringformatMemory(Integer memory)
format Memory
return String.format("%-9s", String.format("%dM", memory));
StringformatMemory(long mem)
format Memory
long kb = mem / 1024;
long mb = kb / 1024;
if (mb > 0)
    return mb + " MB";
else if (kb > 0)
    return kb + " KB";
else
    return mem + " B";
...
StringformatMemorySize(long arg)
Format a memory size with g/m/k quantifiers into its number representation.
if (arg >= 1024 * 1024 * 1024)
    return String.format("%d GB", arg / (1024 * 1024 * 1024));
else if (arg >= 1024 * 1024)
    return String.format("%d MB", arg / (1024 * 1024));
else if (arg >= 1024)
    return String.format("%d KB", arg / (1024));
else
    return String.format("%d", arg);
...