Here you can find the source of simpleMemory()
public static String simpleMemory()
//package com.java2s; //License from project: LGPL public class Main { /**/* ww w. j a va2 s . c o m*/ * Return the memory in a simple format. * The format is used memory/total memory/max memory. * Each memory is formatted using {@link #toSimpleBytes(long)}. * * @return The simple memory. * @author shinobu * @since RELEASE6-0 */ public static String simpleMemory() { StringBuilder memory = new StringBuilder(); Runtime runtime = Runtime.getRuntime(); long maxMemory = runtime.maxMemory(); long totalMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); long usedMemory = totalMemory - freeMemory; memory.append(toSimpleBytes(usedMemory)); memory.append("/"); memory.append(toSimpleBytes(totalMemory)); memory.append("/"); memory.append(toSimpleBytes(maxMemory)); return memory.toString(); } /** * Formats bytes to a simple format. * The number of bytes will be suffixed by "B", "MB", "GB". * The number will always be 0 ~ 2048. * * @param bytes The bytes. * @return The simple bytes. * @author shinobu * @since RELEASE6-0 */ private static String toSimpleBytes(long bytes) { String suffix = "B"; if (bytes > 2048) { bytes /= 1024; suffix = "KB"; if (bytes > 2048) { bytes /= 1024; suffix = "MB"; if (bytes > 2048) { bytes /= 1024; suffix = "GB"; } } } return String.format("%1$d%2$s", bytes, suffix); } }