3 import java.util.Arrays;
6 * IoTString is wraps the underlying byte string. We don't use the
7 * standard String class as we have bytes and not chars.
8 * @author Brian Demsky <bdemsky@uci.edu>
13 final public class IoTString {
21 * Builds an IoTString object around the byte array. This
22 * constructor makes a copy, so the caller is free to modify the byte array.
25 public IoTString(byte[] _array) {
26 array=(byte[]) _array.clone();
27 hashcode=Arrays.hashCode(array);
31 * Converts the String object to a byte representation and stores it
32 * into the IoTString object.
35 public IoTString(String str) {
37 hashcode=Arrays.hashCode(array);
41 * Internal methods to build an IoTString using the byte[] passed
42 * in. Caller is responsible for ensuring the byte[] is never
46 static IoTString shallow(byte[] _array) {
47 IoTString i=new IoTString();
49 i.hashcode = Arrays.hashCode(_array);
54 * Internal method to grab a reference to our byte array. Caller
58 byte[] internalBytes() {
63 * Returns the hashCode as computed by Arrays.hashcode(byte[]).
66 public int hashCode() {
71 * Returns a String representation of the IoTString.
74 public String toString() {
75 return new String(array);
79 * Returns a copy of the underlying byte string.
82 public byte[] getBytes() {
83 return (byte[]) array.clone();
87 * Returns true if two byte strings have the same content.
90 public boolean equals(Object o) {
91 if (o instanceof IoTString) {
92 IoTString i=(IoTString)o;
93 return Arrays.equals(array, i.array);
99 * Returns the length in bytes of the IoTString.
102 public int length() {