--- /dev/null
+// Copyright 2000-2006 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.util;
+
+/** prints numbers (like 1000) as byte sizes (like 1mb) */
+public class ByteSize {
+
+ public static String toString(int bytes) {
+
+ if (bytes < 1024)
+ return bytes+"b";
+
+ if (bytes < 1024 * 1024)
+ return (bytes/1024)+"kb";
+
+ if (bytes < 1024 * 1024 * 1024)
+ return (bytes/(1024*1024))+"mb";
+
+ if (bytes < 1024 * 1024 * 1024 * 1024)
+ return (bytes/(1024*1024*1024))+"gb";
+
+ return bytes+"b";
+ }
+
+}