ST-Developer Java Reference

com.steptools.stdev.keystone
Class Binary

java.lang.Object
  extended by com.steptools.stdev.keystone.Binary
All Implemented Interfaces:
Cloneable

public class Binary
extends Object
implements Cloneable

Represents in instance on an EXPRESS BINARY type. A Binary is a sequence of bits that is used to represent bit masks, or (horrors!) BLOBS. This class provides methods (toString and the constructo) which will convert the Part 21 serialization of Binary objects to and from an instance of this class. Note that the P21 serialization uses 4 bit values for each hex digit, but the access methods implemented in the API use 8-bit bytes for packing the data. The get and put methods deal with 8 bit, and not 4 bit values.


Constructor Summary
Binary(Binary other)
          Create an empty copy of another binary.
Binary(int len, int mask_bits)
          Create a binary object of the specified length
Binary(String p21str)
          Create a Binary object from a Part21-encoded string.
 
Method Summary
 Object clone()
          Create a copy of this object
 boolean equals(Object o)
          Determines if two binaries contain the same values
 byte get(int index)
          Get a sequence of 8 bits from the binary object.
 int getMaskedBits()
          Gets the number of extra bits in the binary
 int hashCode()
          Get the has code for this object.
 boolean isEmpty()
          Determine if this object is empty.
 void set(int index, byte value)
          Set a sequence of 8 bits from the binary object.
 int size()
          Gets the size (in bytes) of the binary.
 int sizeInBits()
          Determines the length of the binary in bits
 int sizeInBytes()
          Determines the length of the binary in bytes
 String toString()
          Convert the binary to a string as specified in Part 21
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Binary

public Binary(String p21str)
       throws BinarySyntaxException
Create a Binary object from a Part21-encoded string.

Parameters:
p21str - A string representation for the binary. This consists of a set of hex digits. The first digit indicates how many of the bits in the second digit are signifigant. Each character in the rest of the string represents four bits of the binary value.
Throws:
BinarySyntaxException

Binary

public Binary(int len,
              int mask_bits)
Create a binary object of the specified length

Parameters:
len - The requested length for the binary in bytes.
mask_bits - Number of bits to ignore.

Binary

public Binary(Binary other)
Create an empty copy of another binary.

Parameters:
other - The object getting copied.
Method Detail

get

public byte get(int index)
Get a sequence of 8 bits from the binary object.

Parameters:
index - The index of the byte to retreive.
Returns:
The requested value.
Throws:
IndexOutOfBoundsException

set

public void set(int index,
                byte value)
Set a sequence of 8 bits from the binary object.

Parameters:
index - The index of the byte to retreive.
value - The value to be set.
Throws:
IndexOutOfBoundsException

size

public int size()
Gets the size (in bytes) of the binary.

Returns:
The size of the binary in bytes.

sizeInBits

public int sizeInBits()
Determines the length of the binary in bits

Returns:
The length of the binary in bits.

sizeInBytes

public int sizeInBytes()
Determines the length of the binary in bytes

Returns:
The length of the binary in bytes.

getMaskedBits

public int getMaskedBits()
Gets the number of extra bits in the binary

Returns:
The number of extra bits.

isEmpty

public boolean isEmpty()
Determine if this object is empty. This should not happen (we should have a null instead, but it could happen, so we have this here for safty.

Returns:
true if the binary is empty.

equals

public boolean equals(Object o)
Determines if two binaries contain the same values

Overrides:
equals in class Object
Parameters:
o - The other object to compare
Returns:
true if the other binary has the same length, and the same bits as this one.

clone

public Object clone()
             throws CloneNotSupportedException
Create a copy of this object

Overrides:
clone in class Object
Returns:
A binary with the same value as this one.
Throws:
CloneNotSupportedException

hashCode

public int hashCode()
Get the has code for this object.

Overrides:
hashCode in class Object
Returns:
The has code for the binary.

toString

public String toString()
Convert the binary to a string as specified in Part 21

Overrides:
toString in class Object
Returns:
The string in part21 format. The first digit is a count of extra bits, followed by the data.

ST-Developer Java Reference