forked from j62/ctbrec
1
0
Fork 0
ctbrec/common/src/main/java/ctbrec/StringUtil.java

31 lines
834 B
Java

package ctbrec;
import java.text.DecimalFormat;
public class StringUtil {
public static boolean isBlank(String s) {
return s == null || s.trim().isEmpty();
}
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;
}
}