jsdai.lang
Class Binary

java.lang.Object
  extended byjsdai.lang.Binary

public final class Binary
extends java.lang.Object

The Binary class represents the EXPRESS data type BINARY. Instances of Binary are constant: their values cannot be changed after they are created.


Constructor Summary
Binary(byte[] str, int size)
          Initializes a newly created Binary object so that it represents the sequence of bits described by the argument of type byte array.
Binary(java.lang.String str)
          Initializes a newly created Binary object so that it represents the sequence of bits described by the String argument.
 
Method Summary
static Binary BitsToBinary(java.lang.String str)
           
 boolean equals(Binary bin)
          Compares this Binary to the specified object of Binary type.
 int getSize()
          Returns the length of the value of this Binary.
 int toByteArray(byte[] byte_array)
          Stores the value of this Binary into submitted byte array.
 java.lang.String toString()
          Returns a String representing the value of this Binary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Binary

public Binary(java.lang.String str)
       throws SdaiException
Initializes a newly created Binary object so that it represents the sequence of bits described by the String argument. A correspondence between a value of binary data type and its String representation is defined as follows. For a sequence of p bits, the string consists of k+1 hexadecimal digits, where k is the smallest integer larger or equal to p/4. The first digit is the value of 4k-p. Other digits are obtained by first left filling the binary with 4k-p zero bits and then dividing the sequence into groups of four bits. Each of these groups gives a separate digit in the string representation.

If the String submitted cannot be mapped to a bit sequence according to the above rules, then SdaiException VA_NVLD is thrown.

Parameters:
str - a String representing the binary value.
Throws:
SdaiException - VA_NVLD, value invalid.
See Also:
Binary(byte [] str, int size)

Binary

public Binary(byte[] str,
              int size)
       throws SdaiException
Initializes a newly created Binary object so that it represents the sequence of bits described by the argument of type byte array. A correspondence between a value of binary data type and its byte array representation is defined as follows. For a sequence of p bits, the byte array consists of k+1 hexadecimal digits, where k is the smallest integer larger or equal to p/4. The first digit is the value of 4k-p. Other digits are obtained by first left filling the binary with 4k-p zero bits and then dividing the sequence into groups of four bits. Each of these groups gives a separate digit stored as a member of byte array.

If the byte array submitted cannot be mapped to a bit sequence according to the above rules, then SdaiException VA_NVLD is thrown.

Parameters:
str - a byte array representing the binary value.
size - the number of bytes representing the binary value.
Throws:
SdaiException - VA_NVLD, value invalid.
See Also:
Binary(String str)
Method Detail

BitsToBinary

public static Binary BitsToBinary(java.lang.String str)
                           throws SdaiException
Throws:
SdaiException

toString

public java.lang.String toString()
Returns a String representing the value of this Binary. For a sequence of p bits, this string consists of k+1 hexadecimal digits, where k is the smallest integer larger or equal to p/4. The first digit is the value of 4k-p. Other digits are obtained by first left filling the binary with 4k-p zero bits and then dividing the sequence into groups of four bits. Each of these groups gives a separate digit in the string representation.

Example:

    Binary bin = ...; // suppose that value is 0100101011
    System.out.println("Binary value: " + bin);
    The following string will be printed:
    Binary value: 212B

Returns:
a string representation of the value of this Binary.
See Also:
toByteArray(byte[]), "ISO 10303-21::7.3.6 Binary"

toByteArray

public int toByteArray(byte[] byte_array)
                throws SdaiException
Stores the value of this Binary into submitted byte array. For a sequence of p bits, this array consists of k+1 hexadecimal digits, where k is the smallest integer larger or equal to p/4. The first digit is the value of 4k-p. Other digits are obtained by first left filling the binary with 4k-p zero bits and then dividing the sequence into groups of four bits. Each of these groups gives a separate digit stored as a member of byte array.

If the size of the array submitted as an argument to this method is too small, then SdaiException VA_NVLD is thrown.

Example:

    Binary bin = ...; // suppose that value is 0100101011
    byte [] bt_array = new byte [5];
    int count = bin.toByteArray(bt_array);
    for (int i = 0; i < count; i++) {
       System.out.println("  i = " + i + "  value = " + (char)bt_array[i]);
    }
    The following lines will be printed:
    i = 0  value = 2
    i = 1  value = 1
    i = 2  value = 2
    i = 3  value = B

Parameters:
byte_array - a byte array submitted to store the value of this Binary.
Returns:
the number of bytes used to store the value of this Binary.
Throws:
SdaiException - VA_NVLD, value invalid.
See Also:
toString(), "ISO 10303-21::7.3.6 Binary"

getSize

public int getSize()
Returns the length of the value of this Binary. The length is equal to the number of bits in the bit sequence representing a value of the binary data type.

Returns:
the length of the sequence of bits represented by this Binary object.

equals

public boolean equals(Binary bin)
Compares this Binary to the specified object of Binary type.

Parameters:
bin - the object to compare this Binary against.
Returns:
true if and only if the argument is not null and represents the same sequence of bits as this Binary object; false otherwise.

Copyright © LKSoftWare GmbH, 1999-2008