From: adam Date: Sat, 2 Dec 2006 08:13:13 +0000 (+0000) Subject: added ByteSize.java X-Git-Url: http://git.megacz.com/?p=org.ibex.util.git;a=commitdiff_plain;h=5ba9f803ce71d4e2d332b4854ddbaece927e8789 added ByteSize.java darcs-hash:20061202081313-5007d-d45df02eb7c625b0cb21f6049ea8d9c481fbaf98.gz --- 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"; + } + +}