## com.ericsson.otp.erlang
Class OtpErlangBitstr

    java.lang.Object
      com.ericsson.otp.erlang.OtpErlangObject
          com.ericsson.otp.erlang.OtpErlangBitstr

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable

Direct Known Subclasses:
  OtpErlangBinary

    public class OtpErlangBitstr

extends OtpErlangObject
implements java.io.Serializable, java.lang.Cloneable

Provides a Java representation of Erlang bitstrs. An Erlang bitstr is an Erlang binary with a length not an integral number of bytes (8-bit). Anything can be represented as a sequence of bytes can be made into an Erlang bitstr.

See Also:
  Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class com.ericsson.otp.erlang.OtpErlangObject
`OtpErlangObject.Hash`

Field Summary
`protected byte[]` `bin`
`protected int` `pad_bits`

Fields inherited from class com.ericsson.otp.erlang.OtpErlangObject
`hashCodeValue`

Constructor Summary
`OtpErlangBitstr(byte[] bin)` Create a bitstr from a byte array
`OtpErlangBitstr(byte[] bin, int pad_bits)` Create a bitstr with pad bits from a byte array.
`OtpErlangBitstr(java.lang.Object o)` Create a bitstr from an arbitrary Java Object.
`OtpErlangBitstr(OtpInputStream buf)` Create a bitstr from a stream containing a bitstr encoded in Erlang external format.

Method Summary
`byte[]` `binaryValue()` Get the byte array from a bitstr, padded with zero bits in the little end of the last byte.
`java.lang.Object` `clone()`
`protected int` `doHashCode()`
`void` `encode(OtpOutputStream buf)` Convert this bitstr to the equivalent Erlang external representation.
`boolean` `equals(java.lang.Object o)` Determine if two bitstrs are equal.
`java.lang.Object` `getObject()` Get the java Object from the bitstr.
`int` `pad_bits()` Get the number of pad bits in the last byte of the bitstr.
`int` `size()` Get the size in whole bytes of the bitstr, rest bits in the last byte not counted.
`java.lang.String` `toString()` Get the string representation of this bitstr object.

Methods inherited from class com.ericsson.otp.erlang.OtpErlangObject
`decode, hashCode`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### bin

    protected byte[] bin

### pad_bits

    protected int pad_bits

Constructor Detail

### OtpErlangBitstr

    public OtpErlangBitstr(byte[] bin)

  Create a bitstr from a byte array

  Parameters:
    `bin` - the array of bytes from which to create the bitstr.

### OtpErlangBitstr

    public OtpErlangBitstr(byte[] bin,
                           int pad_bits)

  Create a bitstr with pad bits from a byte array.

  Parameters:
    `bin` - the array of bytes from which to create the bitstr.
    `pad_bits` - the number of unused bits in the low end of the last byte.

### OtpErlangBitstr

    public OtpErlangBitstr(OtpInputStream buf)
                    throws OtpErlangDecodeException

  Create a bitstr from a stream containing a bitstr encoded in Erlang external format.

  Parameters:
    `buf` - the stream containing the encoded bitstr.
  Throws:
    `OtpErlangDecodeException` - if the buffer does not contain a valid external representation of an Erlang bitstr.

### OtpErlangBitstr

    public OtpErlangBitstr(java.lang.Object o)

  Create a bitstr from an arbitrary Java Object. The object must implement java.io.Serializable or java.io.Externalizable.

  Parameters:
    `o` - the object to serialize and create this bitstr from.

Method Detail

### binaryValue

    public byte[] binaryValue()

  Get the byte array from a bitstr, padded with zero bits in the little end of the last byte.

  Returns:
    the byte array containing the bytes for this bitstr.

### size

    public int size()

  Get the size in whole bytes of the bitstr, rest bits in the last byte not counted.

  Returns:
    the number of bytes contained in the bintstr.

### pad_bits

    public int pad_bits()

  Get the number of pad bits in the last byte of the bitstr. The pad bits are zero and in the little end.

  Returns:
    the number of pad bits in the bitstr.

### getObject

    public java.lang.Object getObject()

  Get the java Object from the bitstr. If the bitstr contains a serialized Java object, then this method will recreate the object.

  Returns:
    the java Object represented by this bitstr, or null if the bitstr does not represent a Java Object.

### toString

    public java.lang.String toString()

  Get the string representation of this bitstr object. A bitstr is printed as #Bin<N>, where N is the number of bytes contained in the object or #bin<N-M> if there are M pad bits.

  Specified by:
    `toString` in class `OtpErlangObject`
  Returns:
    the Erlang string representation of this bitstr.

### encode

    public void encode(OtpOutputStream buf)

  Convert this bitstr to the equivalent Erlang external representation.

  Specified by:
    `encode` in class `OtpErlangObject`
  Parameters:
    `buf` - an output stream to which the encoded bitstr should be written.

### equals

    public boolean equals(java.lang.Object o)

  Determine if two bitstrs are equal. Bitstrs are equal if they have the same byte length and tail length, and the array of bytes is identical.

  Specified by:
    `equals` in class `OtpErlangObject`
  Parameters:
    `o` - the bitstr to compare to.
  Returns:
    true if the bitstrs contain the same bits, false otherwise.

### doHashCode

    protected int doHashCode()

  Overrides:
    `doHashCode` in class `OtpErlangObject`

### clone

    public java.lang.Object clone()

  Overrides:
    `clone` in class `OtpErlangObject`