Class ByteArray


  extended by Object
      extended by ByteArray

public class ByteArray
extends Object

This class implements an facade for byte[]. Size of array is fixed and cannot be changed after it is created.

The single bytes (elements) in this array can be accessed with the operators get and set using brackets.

See Also:
Operators

Constructor Summary
ByteArray(int length)
          Creates a new byte[] with specified length.
 
Method Summary
 ByteArray clear(int fill)
          Fills the whole array with specified byte.
 boolean getBit(int bit)
          Returns the bit at specified index.
 int length()
          Returns the length of this array.
 int operator_get(int index)
          Returns the byte at specified index.
 int operator_set(int index, int value)
          Sets the byte at specified index.
 ByteArray set$(int offset)
          Sets multiple bytes at once, starting from specified offset.
 ByteArray setBit(int bit, boolean enabled)
          Sets the bit at specified index.
 ByteArray setLength(int length)
          Creates a new array with specified length.
 ByteArray sha1()
          Computes digest from this array using SHA1 algorithm.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArray

public ByteArray(int length)
Creates a new byte[] with specified length.

Parameters:
length - Length of array, must be >= 0
Method Detail

operator_get

public int operator_get(int index)
Returns the byte at specified index.

Parameters:
index - Index to array
Returns:
byte at specified index
See Also:
get

operator_set

public int operator_set(int index,
                        int value)
Sets the byte at specified index.

Parameters:
index - Index to array
value - New value for index
Returns:
value parameter
See Also:
set

setLength

public ByteArray setLength(int length)
Creates a new array with specified length. Initial contents are duplicated from this array. If new length is greater than length of this array the new indices are filled with zeros.

Parameters:
length - New length of array
Returns:
new ByteArray instance

length

public int length()
Returns the length of this array.

Returns:
length of array

setBit

public ByteArray setBit(int bit,
                        boolean enabled)
Sets the bit at specified index. This method will create and return new ByteArray if current array does not have space to hold a bit with specified index.

Parameters:
bit - Index of bit to check.
enabled - Bit on/off
Returns:
this ByteArray or new instance if index of bit was larger than available size.
See Also:
getBit(int)

getBit

public boolean getBit(int bit)
Returns the bit at specified index.

Parameters:
bit - Index of bit to check.
Returns:
the value of bit at specified index
See Also:
setBit(int, boolean)

clear

public ByteArray clear(int fill)
Fills the whole array with specified byte.

Parameters:
fill - Filler byte
Returns:
this ByteArray
Since:
2.0.0

set$

public ByteArray set$(int offset)
Sets multiple bytes at once, starting from specified offset. Note that all the arguments must result integers - in some situation the forced cast is needed. Arguments that are out of array range are silently ignored.
 ByteArray hello = new ByteArray(5).set(0, 'H', 'e', 'l', 'l', 'o');
 

Parameters:
offset - Offset to start setting from
Returns:
this ByteArray
Since:
2.0.0

sha1

public ByteArray sha1()
Computes digest from this array using SHA1 algorithm.

Returns:
SHA1 digest, 20 bytes.
Since:
3.0.0