From 79b532d8b6702a5599e7a3eac1416f562405668e Mon Sep 17 00:00:00 2001 From: Tarun Gupta Date: Tue, 23 Jun 2015 22:11:12 +0530 Subject: 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 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 { + + 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 -- cgit v0.10.2-6-g49f6