Package com.ericsson.otp.erlang
Class OtpErlangBitstr
java.lang.Object
com.ericsson.otp.erlang.OtpErlangObject
com.ericsson.otp.erlang.OtpErlangBitstr
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
OtpErlangBinary
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.ericsson.otp.erlang.OtpErlangObject
OtpErlangObject.Hash
-
Field Summary
Fields inherited from class com.ericsson.otp.erlang.OtpErlangObject
hashCodeValue
-
Constructor Summary
ConstructorDescriptionOtpErlangBitstr
(byte[] bin) Create a bitstr from a byte arrayOtpErlangBitstr
(byte[] bin, int pad_bits) Create a bitstr with pad bits from a byte array.Create a bitstr from a stream containing a bitstr encoded in Erlang external format.Create a bitstr from an arbitrary Java Object. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Get the byte array from a bitstr, padded with zero bits in the little end of the last byte.clone()
protected int
void
encode
(OtpOutputStream buf) Convert this bitstr to the equivalent Erlang external representation.boolean
Determine if two bitstrs are equal.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.toString()
Get the string representation of this bitstr object.Methods inherited from class com.ericsson.otp.erlang.OtpErlangObject
bind, decode, hashCode, match
-
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
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
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
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
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 classOtpErlangObject
- Returns:
- the Erlang string representation of this bitstr.
-
encode
Convert this bitstr to the equivalent Erlang external representation.- Specified by:
encode
in classOtpErlangObject
- Parameters:
buf
- an output stream to which the encoded bitstr should be written.
-
equals
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 classOtpErlangObject
- 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 classOtpErlangObject
-
clone
- Overrides:
clone
in classOtpErlangObject
-