summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-17 02:22:32 (GMT)
committerNick Hudson <nick.hudson@isode.com>2015-07-28 13:14:20 (GMT)
commit673655830b0325d964e67fa835ea83f485e9beeb (patch)
tree27e4f8bd20dd9011207641a83212ced393fbada2 /src/com/isode/stroke/base
parent6f84f6a65b8b80e2f599dff76da0cd13fbead611 (diff)
downloadstroke-673655830b0325d964e67fa835ea83f485e9beeb.zip
stroke-673655830b0325d964e67fa835ea83f485e9beeb.tar.bz2
Complete StreamStack and add tests.
TLSLayer could not be updated because it requires TLS to be ported first. Updates other classes, only for having compatibility with SafeByteArray because of updates in Stream Stack. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for StreamStack and XMPPLayer, which passes. Change-Id: I8707fc1f16d622d2a90f6f39f671b7e7c46aa170
Diffstat (limited to 'src/com/isode/stroke/base')
-rw-r--r--src/com/isode/stroke/base/SafeByteArray.java158
1 files changed, 84 insertions, 74 deletions
diff --git a/src/com/isode/stroke/base/SafeByteArray.java b/src/com/isode/stroke/base/SafeByteArray.java
index 74c1848..ac8960f 100644
--- a/src/com/isode/stroke/base/SafeByteArray.java
+++ b/src/com/isode/stroke/base/SafeByteArray.java
@@ -22,83 +22,93 @@ public class SafeByteArray extends ByteArray {
super(s);
}
- public SafeByteArray(ByteArray b) {
- this.append(b.getData());
- }
+ public SafeByteArray(ByteArray b) {
+ this.append(b.getData());
+ }
- /**
- * Creates a new SafeByteArray object containing all
- * the elements from two existing ByteArrays (immutable add).
- *
- * @param a an existing SafeByteArray. Must not be null, but may be empty.
- * @param b an existing SafeByteArray. Must not be null, but may be empty.
- * @return a new SafeByteArray containing all the elements of <em>a</em>
- * followed by all the elements of <em>b</em>.
- */
- public static SafeByteArray plus(SafeByteArray a, SafeByteArray b) {
- SafeByteArray x = new SafeByteArray().append(a.getData());
- x.append(b);
- return x;
- }
-
- /**
- * Updates the SafeByteArray by adding all the elements
- * of another SafeByteArray to the end of the array (mutable add).
- * @param b an existing SafeByteArray. Must not be null, but may be empty
- * @return a reference to the updated object
- */
- public SafeByteArray append(ByteArray b) {
- append(b.getData());
- return this;
- }
+ /**
+ * Constructs a new ByteArray containing the bytes in a user-supplied
+ * byte[]
+ * @param c an array of bytes, which must not be null, but may contain
+ * zero elements.
+ */
+ public SafeByteArray(byte[] c) {
+ super(c);
+ }
- /**
- * Updates the SafeByteArray by adding all the bytes
- * in a byte[] to the end of the array (mutable add).
- *
- * @param b an array of bytes. Must not be null, but may contain zero
- * elements.
- *
- * @return a reference to the updated object
- */
- public SafeByteArray append(byte[] b) {
- return append(b, b.length);
- }
+ /**
+ * Creates a new SafeByteArray object containing all
+ * the elements from two existing ByteArrays (immutable add).
+ *
+ * @param a an existing SafeByteArray. Must not be null, but may be empty.
+ * @param b an existing SafeByteArray. Must not be null, but may be empty.
+ * @return a new SafeByteArray containing all the elements of <em>a</em>
+ * followed by all the elements of <em>b</em>.
+ */
+ public static SafeByteArray plus(SafeByteArray a, SafeByteArray b) {
+ SafeByteArray x = new SafeByteArray().append(a.getData());
+ x.append(b);
+ return x;
+ }
+
+ /**
+ * Updates the SafeByteArray by adding all the elements
+ * of another SafeByteArray to the end of the array (mutable add).
+ * @param b an existing SafeByteArray. Must not be null, but may be empty
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(ByteArray b) {
+ append(b.getData());
+ return this;
+ }
- /** Mutable add */
- public SafeByteArray append(byte[] b, int len) {
- for (int i = 0; i < len; i++) {
- append(b[i]);
- }
- return this;
- }
+ /**
+ * Updates the SafeByteArray by adding all the bytes
+ * in a byte[] to the end of the array (mutable add).
+ *
+ * @param b an array of bytes. Must not be null, but may contain zero
+ * elements.
+ *
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(byte[] b) {
+ return append(b, b.length);
+ }
- /**
- * Updates the SafeByteArray by adding a single byte
- * value to the end of the array (mutable add).
- * @param b a single byte
- * @return a reference to the updated object
- */
- public SafeByteArray append(byte b) {
- dataCopy_ = null; /* Invalidate cache */
- data_.add(Byte.valueOf(b));
- return this;
- }
+ /** Mutable add */
+ public SafeByteArray append(byte[] b, int len) {
+ for (int i = 0; i < len; i++) {
+ append(b[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Updates the SafeByteArray by adding a single byte
+ * value to the end of the array (mutable add).
+ * @param b a single byte
+ * @return a reference to the updated object
+ */
+ public SafeByteArray append(byte b) {
+ dataCopy_ = null; /* Invalidate cache */
+ data_.add(Byte.valueOf(b));
+ return this;
+ }
- /**
- * Updates the SafeByteArray by adding all the bytes
- * obtained by UTF-8 encoding the provided String to the end of the array (mutable add).
- * @param s a String that must not be null.
- * @return a reference to the updated object.
- */
- public SafeByteArray append(String s) {
- byte[] bytes;
- try {
- bytes = s.getBytes("UTF-8");
- } catch (UnsupportedEncodingException ex) {
- throw new IllegalStateException("JVM has no 'UTF-8' encoding");
- }
- append(bytes);
- return this;
- }
+ /**
+ * Updates the SafeByteArray by adding all the bytes
+ * obtained by UTF-8 encoding the provided String to the end of the array (mutable add).
+ * @param s a String that must not be null.
+ * @return a reference to the updated object.
+ */
+ public SafeByteArray append(String s) {
+ byte[] bytes;
+ try {
+ bytes = s.getBytes("UTF-8");
+ } catch (UnsupportedEncodingException ex) {
+ throw new IllegalStateException("JVM has no 'UTF-8' encoding");
+ }
+ append(bytes);
+ return this;
+ }
} \ No newline at end of file