@Test public void testStringify() { assertEquals("1B", stringify(1)); assertEquals("1.00KB", stringify(1024)); assertEquals("1.00MB", stringify(1048576)); assertEquals("1.00GB", stringify(1073741824)); assertEquals("1.00TB", stringify(1099511627776L)); }
public static String stringify(long byteNumber) { if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; } else { return String.valueOf(byteNumber) + "B"; } }
StrUtil { public static String stringify(long byteNumber) { if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; } else { return String.valueOf(byteNumber) + "B"; } } }
StrUtil { public static String stringify(long byteNumber) { if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; } else { return String.valueOf(byteNumber) + "B"; } } private  StrUtil(); }
StrUtil { public static String stringify(long byteNumber) { if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; } else { return String.valueOf(byteNumber) + "B"; } } private  StrUtil(); static String stringify(long byteNumber); static String replaceVariable(final String param); static String compressMiddle(String s, int headLength, int tailLength); }
StrUtil { public static String stringify(long byteNumber) { if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; } else { return String.valueOf(byteNumber) + "B"; } } private  StrUtil(); static String stringify(long byteNumber); static String replaceVariable(final String param); static String compressMiddle(String s, int headLength, int tailLength);  }