summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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