private static String humanReadableByte(final long size) {
    StringBuilder sb = new StringBuilder();
    long tb, gb, mb, kb, b;

    if (size < HConstants.KB_IN_BYTES) {
      sb.append(size);
      sb.append(" B");
      return sb.toString();
    }

    tb = size / HConstants.TB_IN_BYTES;
    gb = (size - HConstants.TB_IN_BYTES * tb) / HConstants.GB_IN_BYTES;
    mb =
      (size - HConstants.TB_IN_BYTES * tb - HConstants.GB_IN_BYTES * gb) / HConstants.MB_IN_BYTES;
    kb = (size - HConstants.TB_IN_BYTES * tb - HConstants.GB_IN_BYTES * gb
      - HConstants.MB_IN_BYTES * mb) / HConstants.KB_IN_BYTES;
    b = (size - HConstants.TB_IN_BYTES * tb - HConstants.GB_IN_BYTES * gb
      - HConstants.MB_IN_BYTES * mb - HConstants.KB_IN_BYTES * kb);

    sb.append(size).append(" B (");
    if (tb > 0) {
      sb.append(tb);
      sb.append("TB");
    }

    if (gb > 0) {
      sb.append(tb > 0 ? " " : "");
      sb.append(gb);
      sb.append("GB");
    }

    if (mb > 0) {
      sb.append(tb + gb > 0 ? " " : "");
      sb.append(mb);
      sb.append("MB");
    }

    if (kb > 0) {
      sb.append(tb + gb + mb > 0 ? " " : "");
      sb.append(kb);
      sb.append("KB");
    }

    if (b > 0) {
      sb.append(tb + gb + mb + kb > 0 ? " " : "");
      sb.append(b);
      sb.append("B");
    }

    sb.append(")");
    return sb.toString();
  }
Convert a long size to a human readable string. Example: 10763632640 -> 10763632640 B (10GB
25MB)
@param size the size in bytes
@return human readable string
hbase-common/src/main/java/org/apache/hadoop/hbase/util/PrettyPrinter.java