ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/installer2/src/net/oni2/aeinstaller/backend/SizeFormatter.java
Revision: 870
Committed: Tue May 14 17:29:19 2013 UTC (12 years, 11 months ago) by alloc
Content type: text/x-java
File size: 888 byte(s)
Log Message:
AEI2.13:
- Fixes startup bug if free space > 1 TiB

File Contents

# Content
1 package net.oni2.aeinstaller.backend;
2
3 /**
4 * @author Christian Illy
5 */
6 public class SizeFormatter {
7 /**
8 * @param sizeVal
9 * Size in Byte
10 * @param digits
11 * Number of digits
12 * @return Formatted value
13 */
14 public static String format(long sizeVal, int digits) {
15 String names[] = { "B", "KiB", "MiB", "GiB", "TiB" };
16 int nameInd = 0;
17 float size = sizeVal;
18 while ((size > 1024) && (nameInd < (names.length - 1))) {
19 nameInd++;
20 size /= 1024;
21 }
22 if (size < 10)
23 return String.format(
24 "%1." + String.valueOf(Math.max(digits - 1, 0)) + "f %s",
25 size, names[nameInd]);
26 else if (size < 100)
27 return String.format(
28 "%1." + String.valueOf(Math.max(digits - 2, 0)) + "f %s",
29 size, names[nameInd]);
30 else
31 return String.format(
32 "%1." + String.valueOf(Math.max(digits - 3, 0)) + "f %s",
33 size, names[nameInd]);
34 }
35 }