public class BinaryString
extends java.lang.Object
This class represents a binary string; a sequence of characters that contains only '0' and '1' characters. It was designed to provide easy access to each bit in an ASN.1 BIT STRING.
Every binary string is internally represented as a StringBuffer,
which has a certain capacity. As long as the length of the character
sequence contained in the binary string does not exceed the capacity, it is
not necessary to allocate a new internal buffer array. If the internal
buffer overflows, it is automatically made larger.
StringBuffer,
BIT_STRING| Constructor and Description |
|---|
BinaryString(int initialCapacity)
Creates a
BinaryString object that holds not characters, but
has the indicated initial capacity. |
BinaryString(java.lang.String binaryString)
Creates a
BinaryString object using the characters contained
in the indicated String. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isBitSet(int bitIndex)
Checks if a given bit in the binary string is set (is '1').
|
void |
setBit(int bitIndex)
Sets a given bit in the binary string (ensures it is '1').
|
java.lang.String |
toString()
Converts a binary string to a
String object. |
public BinaryString(int initialCapacity)
throws java.lang.IllegalArgumentException
BinaryString object that holds not characters, but
has the indicated initial capacity.initialCapacity - the number of characters the binary string is intended to holdjava.lang.IllegalArgumentException - thrown if the initial capacity is a negative numberpublic BinaryString(java.lang.String binaryString)
throws java.lang.IllegalArgumentException,
BinaryStringFormatException
BinaryString object using the characters contained
in the indicated String.binaryString - a String representation of the binary stringjava.lang.IllegalArgumentException - thrown if the binary string parameter is nullBinaryStringFormatException - thrown if the binary string parameter does not represent a binary
string; it contains characters other than '0' or '1'public boolean isBitSet(int bitIndex)
false is
automatically returned.bitIndex - the index of the bit being checkedtrue if the bit is set; false otherwisepublic void setBit(int bitIndex)
If the bit index falls outside currently allocated binary string, its capacity is automatically increased as necessary, '0's are appended up to the indicated bit index and a '1' is appended at the indicated bit index.
bitIndex - the index of the bit being setjava.lang.IllegalArgumentException - thrown if the bit index is negativepublic java.lang.String toString()
String object.toString in class java.lang.Object