|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jasn.BitString
A sequence of bits modelling the ASN.1 BIT STRING type. The BIT STRING type denotes an arbitrary string of bits (ones and zeroes). A BIT STRING value can have any length, including zero.
ABitString differs from the BitSet
class in that the length method of the former returns the
number of bits stored and not the number of bit set.
Each BitString instance has a capacity. The capacity is
the size of the array used to store the bits. It is always at least as large
as the required number of bytes used to store the bits in the sequence. As
bits are added an BitString, its capacity grows automatically.
A BitString is not safe for multithreaded use without external
synchronization.
| Constructor Summary | |
BitString()
Creates a new empty bit sequence with an initial capacity of 32 bits. |
|
BitString(boolean[] bits)
Creates a bit sequence from the specified boolean array. |
|
BitString(int nbits)
Creates an empty bit sequence whose initial size is large enough to explicitly represent bits with indices in the range 0
through nbits-1 inclusive. |
|
| Method Summary | |
void |
add(BitString bs)
Appends all the bits in the specified BitString to the end
of this BitString. |
void |
add(boolean bit)
Appends the specified bit value to the end of this bit string. |
void |
clear(int bitIndex)
Sets the bit specified by the index to false. |
Object |
clone()
Creates and returns a (deep) copy this BitString which is
equal to it. |
boolean |
equals(Object obj)
Compares this object against the specified object. |
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index. |
int |
getByteCount()
Returns the number of bytes needed to store the bits contained in this BitString. |
int |
getUnusedBits()
Returns the number of unused bits in the last byte. |
int |
hashCode()
Returns a hash code value for this BitString. |
int |
length()
Returns the number of bits contained in this BitString. |
void |
set(int bitIndex)
Sets the bit specified by the index to true. |
boolean[] |
toBooleanArray()
Returns a boolean array with the same bit values a this BitString. |
byte[] |
toByteArray()
Returns a byte array representation of this BitString. |
int |
toByteArray(byte[] buf,
int offset)
Packs the bits of this BitString into the specified
destination byte array, starting at offset offset.
|
String |
toString()
Returns a string representation of this BitString. |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public BitString()
public BitString(int nbits)
0
through nbits-1 inclusive.
nbits - the initial size of the bit set.
NegativeArraySizeException - if the specified initial size is
negative.public BitString(boolean[] bits)
| Method Detail |
public int length()
BitString.
BitString.public int getUnusedBits()
0 if
the number of bits stored is a multiple of 8, 8 - length %
8 otherwise.public int getByteCount()
BitString.
public boolean get(int bitIndex)
true if the bit with the index bitIndex is
currently set in this BitSet; otherwise, the result is
false.
bitIndex - the bit index.
IndexOutOfBoundsException - if the specified index is negative or
greater than or equals to the length of this BitString.public void set(int bitIndex)
true.
bitIndex - a bit index.
IndexOutOfBoundsException - if the specified index is negative or
greater than or equals to the length of this BitString.public void clear(int bitIndex)
false.
bitIndex - the index of the bit to be cleared.
IndexOutOfBoundsException - if the specified index is negative or
greater than or equals to the length of this BitString.public void add(boolean bit)
bit - the value of the bit to be appended.public void add(BitString bs)
BitString to the end
of this BitString.
bs - sequence of bits which are to be added to the
BitString.
NullPointerException - if the specified bit string is
null.public byte[] toByteArray()
BitString.
BitString.
public int toByteArray(byte[] buf,
int offset)
BitString into the specified
destination byte array, starting at offset offset.
The bits in the bitstring, commencing with first bit and proceeding to
the trailing bit, are placed in bits 8 to 1 of the byte
buf[offset], followed by bits 8 to 1 of the byte
buf[offset+1], etc.
Note:
buf.
NullPointerException - if buf is null.
IndexOutOfBoundsException - if offset is negative or
greater/equals than/to buf.length.public boolean[] toBooleanArray()
BitString.
public int hashCode()
BitString.
BitString.public boolean equals(Object obj)
true if and only if the argument is not null
and is a Bitset object that has exactly the same sequence of
bits as this bit sequence.
obj - the object to compare with.
true if the objects represent the same sequence of
bits, false otherwise.public Object clone()
BitString which is
equal to it.
BitString.public String toString()
BitString.
BitString.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||