org.apache.directory.shared.asn1.primitives
Class BitString

java.lang.Object
  extended by org.apache.directory.shared.asn1.primitives.BitString
All Implemented Interfaces:
java.io.Serializable

public class BitString
extends java.lang.Object
implements java.io.Serializable

Implement the Bit String primitive type. A BitString is internally stored as an array of int.

Version:
$Rev: 912399 $, $Date: 2010-02-21 21:52:31 +0100 (Sun, 21 Feb 2010) $
Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
static BitString EMPTY_STRING
          A null MutableString
static boolean STREAMED
          A flag to mark the OctetString as Streamed (for OctetString larger than 1024 chars)
 
Constructor Summary
BitString(byte[] bytes)
          Creates a BitString with a value.
BitString(int length)
          Creates a BitString with a specific length (length is the number of bits).
BitString(int length, boolean isStreamed)
          Creates a streamed BitString with a specific length.
 
Method Summary
 void clearBit(int pos)
          Clear a bit at a specified position.
 boolean getBit(int pos)
          Get the bit stored into the BitString at a specific position.
 byte[] getData()
          Get the representation of a BitString
 byte getUnusedBits()
          Get the number of unused bits
 boolean isStreamed()
          Tells if the OctetString is streamed or not
 void setBit(int pos)
          Set a bit at a specified position.
 void setData(byte[] bytes)
          Set a new BitString in the BitString.
 int size()
           
 java.lang.String toString()
          Return a native String representation of the BitString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_STRING

public static final BitString EMPTY_STRING
A null MutableString


STREAMED

public static final boolean STREAMED
A flag to mark the OctetString as Streamed (for OctetString larger than 1024 chars)

See Also:
Constant Field Values
Constructor Detail

BitString

public BitString(int length)
Creates a BitString with a specific length (length is the number of bits).

Parameters:
length - The BitString length (it's a number of bits)

BitString

public BitString(int length,
                 boolean isStreamed)
Creates a streamed BitString with a specific length. Actually, it's just a simple BitString. TODO Implement streaming.

Parameters:
length - The BitString length, in number of bits
isStreamed - Tells if the BitString must be streamed or not

BitString

public BitString(byte[] bytes)
Creates a BitString with a value.

Parameters:
bytes - The value to store. The first byte contains the number of unused bits
Method Detail

setData

public void setData(byte[] bytes)
Set a new BitString in the BitString. It will replace the old BitString, and reset the current length with the new one.

Parameters:
bytes - The string to store

getData

public byte[] getData()
Get the representation of a BitString

Returns:
A byte array which represent the BitString

getUnusedBits

public byte getUnusedBits()
Get the number of unused bits

Returns:
A byte which represent the number of unused bits

setBit

public void setBit(int pos)
Set a bit at a specified position. The bits are stored from left to right. For instance, if we have 10 bits, then they are coded as b0 b1 b2 b3 b4 b5 b6 b7 - b8 b9 x x x x x x

Parameters:
pos - The bit to set

clearBit

public void clearBit(int pos)
Clear a bit at a specified position. The bits are stored from left to right. For instance, if we have 10 bits, then they are coded as b0 b1 b2 b3 b4 b5 b6 b7 - b8 b9 x x x x x x

Parameters:
pos - The bit to clear

getBit

public boolean getBit(int pos)
Get the bit stored into the BitString at a specific position. The bits are stored from left to right, the LSB on the right and the MSB on the left For instance, if we have 10 bits, then they are coded as b9 b8 b7 b6 - b5 b4 b3 b2 - b1 b0 x x - x x x x With '1001 000x', where x is an unused bit, ^ ^ ^ | | | | | | | | +----- getBit(0) = 0 | +---------- getBit(4) = 0 +------------ getBit(6) = 1

Parameters:
pos - The position of the requested bit.
Returns:
true if the bit is set, false otherwise

size

public int size()
Returns:
The number of bytes used to encode this BitString

toString

public java.lang.String toString()
Return a native String representation of the BitString.

Overrides:
toString in class java.lang.Object
Returns:
A String representing the BitString

isStreamed

public boolean isStreamed()
Tells if the OctetString is streamed or not

Returns:
true if the OctetString is streamed.


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.