Here you can find the source of formatFileStats(final String label, final long fileCount, final Object rawSize)
Parameter | Description |
---|---|
label | The label of the object (session, scan, resource, etc.) |
fileCount | The number of files that compose the object. |
rawSize | The size of the files that compose the object. |
public static String formatFileStats(final String label, final long fileCount, final Object rawSize)
//package com.java2s; public class Main { /**/*from w w w . j av a2 s . c o m*/ * Formats an object's file statistics for display. * * @param label The label of the object (session, scan, resource, etc.) * @param fileCount The number of files that compose the object. * @param rawSize The size of the files that compose the object. * @return A formatted display of the file statistics. */ public static String formatFileStats(final String label, final long fileCount, final Object rawSize) { long size = 0; if (rawSize != null) { if (rawSize instanceof Integer) { size = (Integer) rawSize; } else if (rawSize instanceof Long) { size = (Long) rawSize; } } if (label == null || label.equals("") || label.equalsIgnoreCase("total")) { return String.format("%s in %s files", formatSize(size), fileCount); } return String.format("%s: %s in %s files", label, formatSize(size), fileCount); } /** * Takes a size of a file or heap of memory in the form of a long and returns a formatted readable version in the * form of byte units. For example, 46 would become 46B, 1,024 would become 1KB, 1,048,576 would become 1MB, etc. * * @param size The size in bytes to be formatted. * @return A formatted string representing the byte size. */ public static String formatSize(long size) { if (size < 1024) { return size + " B"; } int exp = (int) (Math.log(size) / Math.log(1024)); return String.format("%.1f %sB", size / Math.pow(1024, exp), "KMGTPE".charAt(exp - 1)); } }