inria.util
Class ByteArray

java.lang.Object
  |
  +--inria.util.ByteArray
All Implemented Interfaces:
java.lang.Cloneable

public class ByteArray
extends java.lang.Object
implements java.lang.Cloneable

The ByteArray class represents an array of bytes for fast access in networking packages. ByteArrays are constant; their values cannot be changed after they are created. ByteBuffers support mutable byte arrays.

ByteArray is a good substitute of String in networking packages.


Field Summary
protected  byte[] buff
           
protected static byte caseDiff
           
protected  int count
           
protected  java.lang.String stringValue
           
 
Constructor Summary
protected ByteArray()
          constructs an empty ByteArray object for subclasses.
  ByteArray(byte[] array, int offset, int length)
          constructs a ByteArray object and initializes it from the given array.
  ByteArray(java.lang.String s)
          constructs a ByteArray object and initializes it from the given string.
 
Method Summary
 java.lang.Object clone()
          returns a cloned instance of the current object.
 int compare(ByteArray array)
          compares with the given array.
 int compareIgnoreCase(ByteArray array)
          compares with the given array.
 boolean containedIn(byte[] array, int offset)
          returns true if the given array contains the current array at the given offset.
 boolean containedIn(ByteArray array)
          returns true if the given array contains the current array.
 boolean containedInIgnoreCase(byte[] array, int offset)
          returns true if the given array contains this array at the given offset.
 void copyTo(byte[] array, int offset)
          Copies the byte array to the given byte array.
 boolean endsWith(byte b)
          Tests if this array ends with the specified byte.
 boolean endsWith(ByteArray suffix)
          Tests if this array ends with the specified suffix.
 boolean equals(ByteArray array)
          returns true if the given array equals the current array.
 boolean equalsIgnoreCase(ByteArray s)
          returns true if the given array equals this array.
 int getLength()
          returns the length of data.
 int indexOf(ByteArray str, int from)
          returns the index of the first occurrence of the given array within this array.
 int length()
          returns the length of data.
 boolean startsWith(byte b)
          Tests if this array starts with the specified byte.
 boolean startsWith(ByteArray prefix)
          Tests if this array starts with the specified prefix.
 boolean startsWith(ByteArray prefix, int offset)
          Tests if this array starts with the specified prefix.
 java.lang.String toString()
          returns the string representation of data.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

caseDiff

protected static final byte caseDiff

buff

protected byte[] buff

count

protected int count

stringValue

protected java.lang.String stringValue
Constructor Detail

ByteArray

protected ByteArray()
constructs an empty ByteArray object for subclasses.

ByteArray

public ByteArray(java.lang.String s)
constructs a ByteArray object and initializes it from the given string.
Parameters:
s - the string.

ByteArray

public ByteArray(byte[] array,
                 int offset,
                 int length)
constructs a ByteArray object and initializes it from the given array.
Parameters:
array - the array of bytes.
offset - the offset in the array.
length - the length of bytes.
Method Detail

getLength

public int getLength()
returns the length of data.

length

public int length()
returns the length of data.

equals

public boolean equals(ByteArray array)
returns true if the given array equals the current array. Two ByteArray's are equal if they have the same length and the same sequence of bytes.
Parameters:
array - the array to compare.

compare

public int compare(ByteArray array)
compares with the given array. This is a string-like comparison.
Parameters:
array - the array to compare.

containedIn

public boolean containedIn(ByteArray array)
returns true if the given array contains the current array.
Parameters:
array - the array to compare.

containedIn

public boolean containedIn(byte[] array,
                           int offset)
returns true if the given array contains the current array at the given offset.
Parameters:
array - the array to compare.
offset - the offset in the given array.

equalsIgnoreCase

public boolean equalsIgnoreCase(ByteArray s)
returns true if the given array equals this array. The comparison is case insensitive if characters are present.
Parameters:
s - the array to compare.

containedInIgnoreCase

public boolean containedInIgnoreCase(byte[] array,
                                     int offset)
returns true if the given array contains this array at the given offset. The comparison is case insensitive if characters are present.
Parameters:
array - the array to compare.
offset - the offset in the given array.

compareIgnoreCase

public int compareIgnoreCase(ByteArray array)
compares with the given array. This is a string-like comparison.
Parameters:
array - the array to compare.

startsWith

public boolean startsWith(ByteArray prefix)
Tests if this array starts with the specified prefix.
Parameters:
prefix - the prefix.
Returns:
true if the byte array represented by the argument is a prefix of the sub-array of this object; false otherwise.

startsWith

public boolean startsWith(ByteArray prefix,
                          int offset)
Tests if this array starts with the specified prefix.
Parameters:
prefix - the prefix.
offset - where to begin looking in the array.
Returns:
true if the byte array represented by the argument is a prefix of the sub-array of this object starting at index offset; false otherwise.

endsWith

public boolean endsWith(ByteArray suffix)
Tests if this array ends with the specified suffix.
Parameters:
suffix - the suffix.
Returns:
true if the byte array represented by the argument is a suffix of this array represented by this object; false otherwise.

startsWith

public boolean startsWith(byte b)
Tests if this array starts with the specified byte.
Parameters:
b - the byte value.

endsWith

public boolean endsWith(byte b)
Tests if this array ends with the specified byte.
Parameters:
b - the byte value.

indexOf

public int indexOf(ByteArray str,
                   int from)
returns the index of the first occurrence of the given array within this array. Returns -1 if not found.
Parameters:
str - the array to search.

copyTo

public void copyTo(byte[] array,
                   int offset)
Copies the byte array to the given byte array.
Parameters:
array - the destination byte array.
offset - the offset in the destination byte array.

toString

public java.lang.String toString()
returns the string representation of data.
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
returns a cloned instance of the current object.
Overrides:
clone in class java.lang.Object


JavaTM Reliable MulticastTM Service version 1.1
Copyright (c) 2001, Sun Microsystems Laboratories, All rights reserved.