Package com.oss.asn1

Class BitString

All Implemented Interfaces:
com.oss.asn1.Sizeable, Serializable, Cloneable
Direct Known Subclasses:
ContainingBitString

public class BitString extends AbstractBinary implements com.oss.asn1.Sizeable
The BitString class represents an ASN.1 BIT STRING, an arbitrarily long string of bits, that may or may not be octet-aligned.
Since:
ASN.1/Java 6.0
See Also:
  • Field Summary

    Fields inherited from class com.oss.asn1.AbstractData

    EQUALS, GREATER_THAN, LESS_THAN
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor creates an empty bit string
    BitString(byte[] value)
    Construct from a byte array.
    BitString(byte[] value, int sigBits)
    Construct from a byte array and significant bits.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    clearBit(int bit)
    Set a bit, identified by an index, to 0.
    Clone 'this' object.
    final boolean
    Compare 'this' object to another BitString object to see if their contents are the same.
    final boolean
    getBit(int bit)
    Check whether a bit at some index is 0 or 1.
    final int
    Get the index of rightmost '1' bit in the BitString
    com.oss.metadata.MemberList
    Returns the named bit list for this Bit String type.
    final int
    Deprecated.
    Get the number of significant bits the BitString contains.
    final int
    Get the number of significant bits of BitString
    Returns the name of ASN.1 type this java class represents.
    int
    Returns a hash code for this object
    boolean
    Returns whether the type has a named bit list or has none.
    final void
    setBit(int bit)
    Set a bit, identified by an index, to 1.
    final void
    setSignificantBits(int sigBits)
    Set the significant bits of BitString.
    final void
    setValue(byte[] value)
    Set the value of this object to a byte[].
    final void
    setValue(byte[] value, int sigBits)
    Set the value of this object to a byte[].

    Methods inherited from class com.oss.asn1.AbstractBinary

    byteArrayValue, delete

    Methods inherited from class com.oss.asn1.AbstractData

    equals, isEncodable, isPDU, isValid, toString, toString

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BitString

      public BitString()
      The default constructor creates an empty bit string
    • BitString

      public BitString(byte[] value)
      Construct from a byte array. The significant bits are set to value.length * 8.
      Parameters:
      value - the byte array to set this object to.
    • BitString

      public BitString(byte[] value, int sigBits)
      Construct from a byte array and significant bits.
      Parameters:
      value - the byte array to set this object to.
      sigBits - the number of significant bits.
  • Method Details

    • clone

      public BitString clone()
      Clone 'this' object.
      Overrides:
      clone in class AbstractBinary
      Returns:
      deep copy of 'this' object.
    • setValue

      public final void setValue(byte[] value)
      Set the value of this object to a byte[].
      Overrides:
      setValue in class AbstractBinary
      Parameters:
      value - the value to set this object to.
    • setValue

      public final void setValue(byte[] value, int sigBits)
      Set the value of this object to a byte[].
      Parameters:
      value - the value to set this object to.
      sigBits - the number of significant bits.
    • getBit

      public final boolean getBit(int bit)
      Check whether a bit at some index is 0 or 1.
      Parameters:
      bit - the index of the bit to check.
      Returns:
      true is returned if the bit at the index is set to 1, otherwise false is returned.
    • setBit

      public final void setBit(int bit)
      Set a bit, identified by an index, to 1.
      Parameters:
      bit - the index of the bit to set to 1.
    • clearBit

      public final void clearBit(int bit)
      Set a bit, identified by an index, to 0.
      Parameters:
      bit - the index of the bit to clear.
    • getSignificantBits

      @Deprecated public final int getSignificantBits()
      Deprecated.
      Get the number of significant bits the BitString contains. This method is deprecated. Use the getSize method instead.
      Returns:
      integer value indicating the number of significant bits.
    • setSignificantBits

      public final void setSignificantBits(int sigBits)
      Set the significant bits of BitString.
      Parameters:
      sigBits - an integer value indicating the number of significant bits to set.
    • getSize

      public final int getSize()
      Get the number of significant bits of BitString
      Specified by:
      getSize in interface com.oss.asn1.Sizeable
      Returns:
      integer value indicating the number of significant bits.
    • getLastBit

      public final int getLastBit()
      Get the index of rightmost '1' bit in the BitString
      Returns:
      integer value indicating the index of rightmost bit set to '1'.
    • equalTo

      public final boolean equalTo(BitString that)
      Compare 'this' object to another BitString object to see if their contents are the same. If ASN.1 definition of a BIT STRING has named bits then the comparison ignores trailing zero bits in the BIT STRING value.
      Parameters:
      that - the BitString object to compare 'this' object to.
      Returns:
      true if contents of both objects are the same.
    • hasNamedBits

      public boolean hasNamedBits()
      Returns whether the type has a named bit list or has none.
      Returns:
      true if the type has named bit list.
    • getNamedBits

      public com.oss.metadata.MemberList getNamedBits()
      Returns the named bit list for this Bit String type. Returns null if there is no named bit list.
      Returns:
      named bit list.
    • hashCode

      public int hashCode()
      Returns a hash code for this object
      Overrides:
      hashCode in class AbstractBinary
      Returns:
      a hash code for this object
    • getTypeName

      public String getTypeName()
      Returns the name of ASN.1 type this java class represents.
      Overrides:
      getTypeName in class AbstractData
      Returns:
      the name of the ASN.1 type.