List of utility methods to do Size
String | padString(String stringToPad, int size) Method "padString". return String.format("%" + size + "s", stringToPad); |
double[][] | read(byte[] input, int size) read try (ByteArrayInputStream inputStream = new ByteArrayInputStream(input)) { return read(inputStream, size); |
String | readableBytes(long byteSize) Formats byte size in nice format if (byteSize < 0l) { return "invalid"; if (byteSize < 1l) { return "empty"; float byteSizeF = new java.lang.Float(byteSize).floatValue(); String unit = "bytes"; ... |
String | readableSize(long num) Convert the given size into a human readable string. float l = num; NumberFormat formatter = (NumberFormat) FORMATTER.clone(); if (l < 1024) { return formatter.format(l) + " bytes"; } else if (l < 1048576) { return (formatter.format(l / 1024) + " KiB"); } else { return (formatter.format(l / 1048576) + " MiB"); ... |
String | readableSize(long size) readable Size NumberFormat formatter = NumberFormat.getNumberInstance(Locale.ROOT); formatter.setMaximumFractionDigits(2); if (size / (1024 * 1024 * 1024) > 0) { return formatter.format(size * 1.0d / (1024 * 1024 * 1024)) + " GB"; } else if (size / (1024 * 1024) > 0) { return formatter.format(size * 1.0d / (1024 * 1024)) + " MB"; } else if (size / 1024 > 0) { return formatter.format(size * 1.0d / 1024) + " KB"; ... |
String | readableSize(long size) Return human readable file size. if (size <= 1) return size + " byte"; final String[] units = new String[] { "bytes", "KB", "MB", "GB", "TB", "PB", "EB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.##").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
String | readableSize(long size, DecimalFormat format) readable Size if (size <= 0) return "0"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return format.format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
String | renderNumber(int n, int size) render Number NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumIntegerDigits(size);
nf.setGroupingUsed(false);
return nf.format(n);
|
String | size(long l) size String dsize = ""; long k = l; double m = l / 1024.0; double g = l / 1048576.0; double t = l / 1073741824.0; DecimalFormat dec = new DecimalFormat("0.00"); if (k > 1) { dsize = dec.format(k).concat(" KB"); ... |
String | size2human(long size) sizehuman if (size > SIZE_GIGABYTE) { DecimalFormat df = new DecimalFormat("#.00"); return df.format(((size + SIZE_GIGABYTE / 2) / SIZE_GIGABYTE)) + " GB"; if (size > SIZE_MEGABYTE) { return ((size + SIZE_MEGABYTE / 2) / SIZE_MEGABYTE) + " MB"; return ((size + SIZE_KILOBYTE / 2) / SIZE_KILOBYTE) + " KB"; ... |