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
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')
-rw-r--r--src/com/isode/stroke/base/FileSize.java21
-rw-r--r--src/com/isode/stroke/base/SafeString.java31
-rw-r--r--src/com/isode/stroke/base/StartStoppable.java13
-rwxr-xr-xsrc/com/isode/stroke/base/StartStopper.java25
-rw-r--r--src/com/isode/stroke/base/Tristate.java18
5 files changed, 108 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
diff --git a/src/com/isode/stroke/base/SafeString.java b/src/com/isode/stroke/base/SafeString.java
new file mode 100644
index 0000000..3640671
--- /dev/null
+++ b/src/com/isode/stroke/base/SafeString.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011-2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.base;
+
+import com.isode.stroke.base.SafeByteArray;
+
+public class SafeString {
+
+ private SafeByteArray data;
+
+ public SafeString(SafeByteArray data) {
+ this.data = data;
+ }
+
+ public SafeString(String s) {
+ this.data = new SafeByteArray(s);
+ }
+
+ public SafeByteArray getData() {
+ return data;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/base/StartStoppable.java b/src/com/isode/stroke/base/StartStoppable.java
new file mode 100644
index 0000000..1c6c404
--- /dev/null
+++ b/src/com/isode/stroke/base/StartStoppable.java
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.base;
+
+public interface StartStoppable {
+
+ void start();
+ void stop();
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/base/StartStopper.java b/src/com/isode/stroke/base/StartStopper.java
new file mode 100755
index 0000000..3f66ce9
--- /dev/null
+++ b/src/com/isode/stroke/base/StartStopper.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.base;
+
+import com.isode.stroke.network.Timer;
+import com.isode.stroke.base.StartStoppable;
+
+public class StartStopper<T extends StartStoppable> {
+
+ private T target;
+
+ public StartStopper(T target) {
+ this.target = target;
+ target.start();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/base/Tristate.java b/src/com/isode/stroke/base/Tristate.java
new file mode 100644
index 0000000..edfba92
--- /dev/null
+++ b/src/com/isode/stroke/base/Tristate.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.base;
+
+public enum Tristate {
+ Yes,
+ No,
+ Maybe
+}; \ No newline at end of file