NO-JIRA support 0 in human readable byte calculation

This commit is contained in:
Justin Bertram 2020-01-08 12:36:52 -06:00
parent 1304dbd539
commit 0293d80574
3 changed files with 6 additions and 1 deletions

View File

@ -451,6 +451,10 @@ public class ByteUtil {
}
public static String getHumanReadableByteCount(long bytes) {
if (bytes == 0) {
return "0B";
}
int i = 0;
while (i < BYTE_MAGNITUDES.length && BYTE_MAGNITUDES[i] > bytes) {
i++;

View File

@ -27,6 +27,7 @@ public class HumanReadableByteCountTest {
public void test() {
String[] suffixes = new String[] {"K", "M", "G", "T", "P", "E"};
assertEquals("0B", ByteUtil.getHumanReadableByteCount(0));
assertEquals("999.0B", ByteUtil.getHumanReadableByteCount(999));
assertEquals("500.0B", ByteUtil.getHumanReadableByteCount(500));

View File

@ -201,7 +201,7 @@ public final class PagingManagerImpl implements PagingManager {
public void tick(long usableSpace, long totalSpace) {
diskUsableSpace = usableSpace;
diskTotalSpace = totalSpace;
logger.tracef("Tick:: usable space at %f, total space at %f", ByteUtil.getHumanReadableByteCount(usableSpace), ByteUtil.getHumanReadableByteCount(totalSpace));
logger.tracef("Tick:: usable space at %s, total space at %s", ByteUtil.getHumanReadableByteCount(usableSpace), ByteUtil.getHumanReadableByteCount(totalSpace));
}
@Override