@Test public void testBytesHumanReadable() throws Exception { assertEquals("1 B", HoodUtil.humanReadableByteCount(1, false)); assertEquals("2 B", HoodUtil.humanReadableByteCount(2, false)); assertEquals("1023 B", HoodUtil.humanReadableByteCount(1023, false)); assertEquals("1.0 KiB", HoodUtil.humanReadableByteCount(1024, false)); assertEquals("1.0 MiB", HoodUtil.humanReadableByteCount(1024 * 1024, false)); assertEquals("1.0 GiB", HoodUtil.humanReadableByteCount(1024 * 1024 * 1024, false)); assertEquals("1 B", HoodUtil.humanReadableByteCount(1, true)); assertEquals("2 B", HoodUtil.humanReadableByteCount(2, true)); assertEquals("999 B", HoodUtil.humanReadableByteCount(999, true)); assertEquals("1.0 kB", HoodUtil.humanReadableByteCount(1000, true)); assertEquals("1.0 MB", HoodUtil.humanReadableByteCount(1000 * 1000, true)); assertEquals("1.0 GB", HoodUtil.humanReadableByteCount(1000 * 1000 * 1000, true)); }
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(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); }
HoodUtil { 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(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); } }
HoodUtil { 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(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); } private  HoodUtil(); }
HoodUtil { 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(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); } private  HoodUtil(); static String byteToHex(byte[] bytes); static T getConditionally(T object, boolean shouldReturnEntry); static Locale getCurrentLocale(Context ctx); static String humanReadableByteCount(long bytes, boolean si); static String millisToDaysHoursMinString(long millis); static String toSimpleDateTimeFormat(long millisEpochUtc); static String obfuscateAndShorten(@Nullable String original, int maxCharLengthLeftOrRight,
                                             char obfuscationChar); }
HoodUtil { 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(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); } private  HoodUtil(); static String byteToHex(byte[] bytes); static T getConditionally(T object, boolean shouldReturnEntry); static Locale getCurrentLocale(Context ctx); static String humanReadableByteCount(long bytes, boolean si); static String millisToDaysHoursMinString(long millis); static String toSimpleDateTimeFormat(long millisEpochUtc); static String obfuscateAndShorten(@Nullable String original, int maxCharLengthLeftOrRight,
                                             char obfuscationChar);  }