All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.talk2object.util.ByteSizeUtil Maven / Gradle / Ivy

The newest version!
package com.talk2object.util;

public class ByteSizeUtil {

	public static String humanReadableByteCount(long bytes, boolean si) {
		int unit = si ? 1000 : 1024;
		if (bytes < unit)
			return bytes + " B";
		int exp = (int) (Math.log(bytes) / Math.log(unit));
		String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1)
				+ (si ? "" : "i");
		return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy