Author: nextgens
Date: 2008-08-14 19:58:24 +0000 (Thu, 14 Aug 2008)
New Revision: 21863
Modified:
trunk/freenet/src/freenet/support/SizeUtil.java
Log:
Update SizeUtil ... We might need to get a value without any space
Modified: trunk/freenet/src/freenet/support/SizeUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/SizeUtil.java 2008-08-14 19:39:03 UTC
(rev 21862)
+++ trunk/freenet/src/freenet/support/SizeUtil.java 2008-08-14 19:58:24 UTC
(rev 21863)
@@ -10,7 +10,17 @@
return formatSize(sz, false);
}
+ public static String formatSize(boolean withoutSpace, long sz) {
+ String[] result = _formatSize(sz);
+ return result[0].concat(result[1]);
+ }
+
public static String formatSize(long sz, boolean useNonBreakingSpace) {
+ String[] result = _formatSize(sz);
+ return result[0].concat((useNonBreakingSpace ? "\u00a0" : "
")).concat(result[1]);
+ }
+
+ public static String[] _formatSize(long sz) {
long s = 1;
int i;
for(i=0;i<SizeUtil.suffixes.length;i++) {
@@ -24,23 +34,19 @@
s /= 1024; // we use the previous unit
if (s == 1) // Bytes? Then we don't need real numbers with a
comma
{
- return sz + " " + SizeUtil.suffixes[0];
+ return new String[] { String.valueOf(sz),
SizeUtil.suffixes[0] };
}
else
{
double mantissa = (double)sz / (double)s;
- String o = Double.toString(mantissa);
+ String o = String.valueOf(mantissa);
if(o.indexOf('.') == 3)
o = o.substring(0, 3);
else if((o.indexOf('.') > -1) && (o.indexOf('E') == -1)
&& (o.length() > 4))
o = o.substring(0, 4);
if(i < SizeUtil.suffixes.length) // handle the case
where the mantissa is Infinity
- if(useNonBreakingSpace) {
- o += '\u00a0' + SizeUtil.suffixes[i];
- } else {
- o += ' ' + SizeUtil.suffixes[i];
- }
- return o;
+ return new String[] { o , SizeUtil.suffixes[i]
};
+ return new String[] { o , "" };
}
}
}