001package org.gbif.utils;
002
003public class HumanSize {
004  private static final int unit = 1024;
005
006  public static String bytes(long bytes) {
007    if (bytes < unit) return bytes + " B";
008    int exp = (int) (Math.log(bytes) / Math.log(unit));
009    char pre = "kMGTPE".charAt(exp-1);
010    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
011  }
012}