@Test public void testHumanReadableByteCount() { assertEquals("0.0 B", NumericUtils.humanReadableByteCount(0)); assertEquals("27.0 B", NumericUtils.humanReadableByteCount(27)); assertEquals("1023.0 B", NumericUtils.humanReadableByteCount(1023)); assertEquals("1.0 KB", NumericUtils.humanReadableByteCount(1024)); assertEquals("108.0 KB", NumericUtils.humanReadableByteCount(110592)); assertEquals("27.0 GB", NumericUtils.humanReadableByteCount(28991029248L)); assertEquals("1.7 TB", NumericUtils.humanReadableByteCount(1855425871872L)); assertEquals("8.0 EB", NumericUtils.humanReadableByteCount(9223372036854775807L)); }
public static String humanReadableByteCount(double bytes) { if (bytes < 1024) { return String.format("%.1f B", bytes); } int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); }
NumericUtils { public static String humanReadableByteCount(double bytes) { if (bytes < 1024) { return String.format("%.1f B", bytes); } int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); } }
NumericUtils { public static String humanReadableByteCount(double bytes) { if (bytes < 1024) { return String.format("%.1f B", bytes); } int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); }  }
NumericUtils { public static String humanReadableByteCount(double bytes) { if (bytes < 1024) { return String.format("%.1f B", bytes); } int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); }  static String humanReadableByteCount(double bytes); static long getMessageDigestHash(final String algorithmName, final String string); static long asLong(byte[] bytes); static long padToLong(byte[] bytes); }
NumericUtils { public static String humanReadableByteCount(double bytes) { if (bytes < 1024) { return String.format("%.1f B", bytes); } int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); }  static String humanReadableByteCount(double bytes); static long getMessageDigestHash(final String algorithmName, final String string); static long asLong(byte[] bytes); static long padToLong(byte[] bytes);  }