From 5ba9f803ce71d4e2d332b4854ddbaece927e8789 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 2 Dec 2006 08:13:13 +0000 Subject: [PATCH] added ByteSize.java darcs-hash:20061202081313-5007d-d45df02eb7c625b0cb21f6049ea8d9c481fbaf98.gz --- src/org/ibex/util/ByteSize.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/org/ibex/util/ByteSize.java 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"; + } + +} -- 1.7.10.4