List of utility methods to do Long Number Readable Format
String | formatBytes(long l) Metodo para fazer a conversao de bytes if (l == 1L) return String.format("%d byte", new Object[] { Long.valueOf(l) }); if (l < 1024L) return String.format("%d bytes", new Object[] { Long.valueOf(l) }); if (l < 0x100000L && l % 1024L == 0L) return String.format("%.0f KB", new Object[] { Double.valueOf((double) l / 1024D) }); if (l < 0x100000L) return String.format("%.1f KB", new Object[] { Double.valueOf((double) l / 1024D) }); ... |
String | formatBytes(long size) Returns a human-readable version of the file size, where the input represents a specific number of bytes. String display; if (size / ONE_GB > 0) { display = String.format("%.2f", (size + 0.0) / ONE_GB) + " GB"; } else if (size / ONE_MB > 0) { display = String.format("%.2f", (size + 0.0) / ONE_MB) + " MB"; } else if (size / ONE_KB > 0) { display = String.format("%.2f", (size + 0.0) / ONE_KB) + " KB"; } else { ... |
String | getHumanReadable(long ts, boolean addUTC) Gets the human redable version of timestamp expressed in miliseconds. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String humanRedable = sdf.format(new Date(ts)); humanRedable += "T"; sdf = new SimpleDateFormat("HH:mm:ss.S"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); humanRedable += sdf.format(new Date(ts)) + (addUTC ? "Z" : ""); return humanRedable; ... |
String | getHumanReadableFileSize(Long fileSize) get Human Readable File Size if (fileSize == null) return null; return getHumanReadableFileSize(fileSize.longValue()); |
String | getHumanReadableIfSpeed(long ifSpeed) Method used to convert an integer bits-per-second value to a more readable vale using commonly recognized abbreviation for network interface speeds. DecimalFormat formatter; double displaySpeed; String units; if (ifSpeed >= 1000000000L) { if ((ifSpeed % 1000000000L) == 0) { formatter = s_noDigitsAfterDecimal; } else { formatter = s_oneDigitAfterDecimal; ... |
String | getHumanReadableSize(long bytes) Converts a long number representing bytes into human readable format. long mb = (long) Math.pow(2, 20); long kb = (long) Math.pow(2, 10); long gb = (long) Math.pow(2, 30); long tb = (long) Math.pow(2, 40); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(1); double relSize = 0.0d; long abytes = Math.abs(bytes); ... |
String | getHumanReadableSize(long fileSize) get Human Readable Size String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int unitIndex = (int) (Math.log10(fileSize) / 3); double unitValue = 1 << (unitIndex * 10); return new DecimalFormat("#,##0.#").format(fileSize / unitValue) + " " + units[unitIndex]; |
String | getHumanReadableSize(long size, long unit, String unitName) get Human Readable Size if (size == 0) { return "0"; if (size / unit >= 1) { double value = size / (double) unit; DecimalFormat df = new DecimalFormat("######.##" + unitName); return df.format(value); return null; |
String | getHumanSize(long size) get Human Size int sizeToStringLength = String.valueOf(size).length(); String humanSize = ""; DecimalFormat formatter = new DecimalFormat("##0.##"); if (sizeToStringLength > 9) { humanSize += formatter.format((double) size / (1024 * 1024 * 1024)) + " GB"; } else if (sizeToStringLength > 6) { humanSize += formatter.format((double) size / (1024 * 1024)) + " MB"; } else if (sizeToStringLength > 3) { ... |
String | getMaxHeap(String message) get Max Heap return "Max heap size (" + message + ") " + readableFileSize(Runtime.getRuntime().maxMemory()); |