Class OtpErlangBitstr

java.lang.Object
com.ericsson.otp.erlang.OtpErlangObject
com.ericsson.otp.erlang.OtpErlangBitstr
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
OtpErlangBinary

public class OtpErlangBitstr extends OtpErlangObject
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:
  • Field Details

    • bin

      protected byte[] bin
    • pad_bits

      protected int pad_bits
  • Constructor Details

    • 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(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 Details

    • 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 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 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(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 Object clone()
      Overrides:
      clone in class OtpErlangObject