summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-23 16:41:12 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-07-06 13:28:03 (GMT)
commit79b532d8b6702a5599e7a3eac1416f562405668e (patch)
tree26a19cb73e7e3553d6c09b2edf5a2979bcefd1e6 /src/com/isode/stroke/base/FileSize.java
parent665fc753249c848637adb7f5d44a68b77d4c642e (diff)
downloadstroke-79b532d8b6702a5599e7a3eac1416f562405668e.zip
stroke-79b532d8b6702a5599e7a3eac1416f562405668e.tar.bz2
Add Base Functionalities.
Adds FileSize, SafeString, StartStoppable, StartStopper and TriState. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: None. Change-Id: I94020700a77bb33dab39fb838eefc96c07b73868
Diffstat (limited to 'src/com/isode/stroke/base/FileSize.java')
-rw-r--r--src/com/isode/stroke/base/FileSize.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/com/isode/stroke/base/FileSize.java b/src/com/isode/stroke/base/FileSize.java
new file mode 100644
index 0000000..c332626
--- /dev/null
+++ b/src/com/isode/stroke/base/FileSize.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2010-2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+package com.isode.stroke.base;
+
+public class FileSize {
+
+ public static String formatSize(long bytes) {
+ char siPrefix[] = {'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
+ int power = 0;
+ double engBytes = (double)bytes;
+ while (engBytes >= 1000) {
+ ++power;
+ engBytes = (double)(engBytes / 1000.0);
+ }
+ return String.format("%.1f", engBytes) + (power > 0 ? (siPrefix[power-1] + "B") : "" );
+ }
+} \ No newline at end of file