X-Git-Url: http://git.megacz.com/?p=org.ibex.util.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FByteSize.java;fp=src%2Forg%2Fibex%2Futil%2FByteSize.java;h=2f1c003a82b5776436c2c1a79b9010bb47d3ece5;hp=0000000000000000000000000000000000000000;hb=5ba9f803ce71d4e2d332b4854ddbaece927e8789;hpb=c949ee89f3a02b26863803c52ce1a0a725014911 diff --git a/src/org/ibex/util/ByteSize.java b/src/org/ibex/util/ByteSize.java new file mode 100644 index 0000000..2f1c003 --- /dev/null +++ b/src/org/ibex/util/ByteSize.java @@ -0,0 +1,27 @@ +// 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"; + } + +}