diff --git a/client/src/main/java/ctbrec/ui/RecordingsTab.java b/client/src/main/java/ctbrec/ui/RecordingsTab.java index 6581bcb5..b60d439b 100644 --- a/client/src/main/java/ctbrec/ui/RecordingsTab.java +++ b/client/src/main/java/ctbrec/ui/RecordingsTab.java @@ -160,20 +160,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { if(empty || sizeInByte == null) { setText(null); } else { - DecimalFormat df = new DecimalFormat("0.00"); - String unit = "Bytes"; - double size = sizeInByte.doubleValue(); - if(size > 1024.0 * 1024 * 1024) { - size = size / 1024.0 / 1024 / 1024; - unit = "GiB"; - } else if(size > 1024.0 * 1024) { - size = size / 1024.0 / 1024; - unit = "MiB"; - } else if(size > 1024.0) { - size = size / 1024.0; - unit = "KiB"; - } - setText(df.format(size) + ' ' + unit); + setText(StringUtil.formatSize(sizeInByte)); } } }; diff --git a/common/src/main/java/ctbrec/StringUtil.java b/common/src/main/java/ctbrec/StringUtil.java index 229e44b1..d9ae9796 100644 --- a/common/src/main/java/ctbrec/StringUtil.java +++ b/common/src/main/java/ctbrec/StringUtil.java @@ -1,5 +1,7 @@ package ctbrec; +import java.text.DecimalFormat; + public class StringUtil { public static boolean isBlank(String s) { return s == null || s.trim().isEmpty(); @@ -8,4 +10,21 @@ public class StringUtil { public static boolean isNotBlank(String s) { return !isBlank(s); } + + public static String formatSize(Number sizeInByte) { + DecimalFormat df = new DecimalFormat("0.00"); + String unit = "Bytes"; + double size = sizeInByte.doubleValue(); + if(size > 1024.0 * 1024 * 1024) { + size = size / 1024.0 / 1024 / 1024; + unit = "GiB"; + } else if(size > 1024.0 * 1024) { + size = size / 1024.0 / 1024; + unit = "MiB"; + } else if(size > 1024.0) { + size = size / 1024.0; + unit = "KiB"; + } + return df.format(size) + ' ' + unit; + } }