public final class ByteArrayBitStreamWriter extends java.lang.Object implements BitStreamWriter
Modifier and Type | Field and Description |
---|---|
protected int |
bitOffset
The current bit offset.
|
protected static byte |
BYTE_MOD_MASK
Byte value used for modulus calculations.
|
protected int |
bytePosition
The current byte position.
|
protected static java.lang.String |
DEFAULT_CHARSET_NAME
The default character set.
|
Constructor and Description |
---|
ByteArrayBitStreamWriter()
Constructs a new byte array bit stream writer with default capacity and the default endian byte order.
|
ByteArrayBitStreamWriter(int initialCapacity)
Constructs a new byte array bit stream writer with the given buffer capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
alignTo(int alignVal)
Aligns the bit position according to the aligning value.
|
protected static void |
checkRange(int numBits)
Checks if the given numBits value is situated in the range 0 to 64.
|
protected static void |
checkUnsignedRange(int numBits)
Checks if the given numBits value is situated in the range 0 to 63.
|
void |
close() |
int |
getBitOffset()
Gets the current bit offset.
|
long |
getBitPosition()
Gets the current bit position.
|
int |
getBytePosition()
Gets the current byte position.
|
void |
setBitPosition(long bitPosition)
Sets the bit position to the given value.
|
byte[] |
toByteArray()
Returns the underlying buffer content as byte array.
|
void |
writeBigInteger(java.math.BigInteger value,
int numBits)
Writes a given big integer value with the given number of bits to the underlying storage.
|
void |
writeBitBuffer(BitBuffer bitBuffer)
Writes a bit buffer to the underlying storage.
|
void |
writeBits(long value,
int numBits)
Writes the given value with the given number of unsigned bits to the underlying storage.
|
void |
writeBool(boolean value)
Writes a boolean value to the underlying storage.
|
void |
writeByte(byte v)
Writes a signed byte to the underlying storage.
|
void |
writeBytes(byte[] value)
Writes a Zserio bytes to the underlying storage.
|
void |
writeFloat16(float value)
Writes a 16-bit float value to the underlying storage.
|
void |
writeFloat32(float value)
Writes a 32-bit float value to the underlying storage.
|
void |
writeFloat64(double value)
Writes a 64-bit float value to the underlying storage.
|
void |
writeInt(int v)
Writes a signed integer to the underlying storage.
|
void |
writeLong(long v)
Writes a signed long to the underlying storage.
|
void |
writeShort(short v)
Writes a signed short to the underlying storage.
|
void |
writeSignedBits(long value,
int numBits)
Writes the given value with the given number of signed bits to the underlying storage.
|
void |
writeString(java.lang.String value)
Writes a Zserio string to the underlying storage in UTF-8 encoding.
|
void |
writeUnsignedByte(short value)
Writes an unsigned byte to the underlying storage.
|
void |
writeUnsignedInt(long value)
Writes an unsigned integer to the underlying storage.
|
void |
writeUnsignedShort(int value)
Writes an unsigned short to the underlying storage.
|
void |
writeVarInt(long value)
Writes a variable signed integer value to the underlying storage.
|
void |
writeVarInt16(short value)
Writes a variable 16 bit integer value to the underlying storage.
|
void |
writeVarInt32(int value)
Writes a variable 32 bit integer value to the underlying storage.
|
void |
writeVarInt64(long value)
Writes a variable 64 bit integer value to the underlying storage.
|
void |
writeVarSize(int value)
Writes a variable size integer value to the underlying storage.
|
void |
writeVarUInt(java.math.BigInteger value)
Writes a variable unsigned integer value to the underlying storage.
|
void |
writeVarUInt16(short value)
Writes a variable 16 bit unsigned integer value to the underlying storage.
|
void |
writeVarUInt32(int value)
Writes a variable 32 bit unsigned integer value to the underlying storage.
|
void |
writeVarUInt64(long value)
Writes a variable 64 bit unsigned integer value to the underlying storage.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBitPosition, getBytePosition, setBitPosition
protected int bytePosition
protected int bitOffset
protected static final java.lang.String DEFAULT_CHARSET_NAME
protected static final byte BYTE_MOD_MASK
public ByteArrayBitStreamWriter()
public ByteArrayBitStreamWriter(int initialCapacity)
initialCapacity
- Underlying byte array capacity in bytes.public void writeSignedBits(long value, int numBits) throws java.io.IOException
BitStreamWriter
writeSignedBits
in interface BitStreamWriter
value
- Value to write.numBits
- Number of bits for the value to write.java.io.IOException
- If the writing failed.public void writeBits(long value, int numBits) throws java.io.IOException
BitStreamWriter
writeBits
in interface BitStreamWriter
value
- Value to write.numBits
- Number of bits for the value to write.java.io.IOException
- If the writing failed.public void writeByte(byte v) throws java.io.IOException
BitStreamWriter
writeByte
in interface BitStreamWriter
v
- Signed byte value to write.java.io.IOException
- If the writing failed.public void writeUnsignedByte(short value) throws java.io.IOException
BitStreamWriter
writeUnsignedByte
in interface BitStreamWriter
value
- Unsigned byte value to write.java.io.IOException
- If the writing failed.public void writeShort(short v) throws java.io.IOException
BitStreamWriter
writeShort
in interface BitStreamWriter
v
- Signed short value to write.java.io.IOException
- If the writing failed.public void writeUnsignedShort(int value) throws java.io.IOException
BitStreamWriter
writeUnsignedShort
in interface BitStreamWriter
value
- Unsigned short value to write.java.io.IOException
- If the writing failed.public void writeInt(int v) throws java.io.IOException
BitStreamWriter
writeInt
in interface BitStreamWriter
v
- Signed integer value to write.java.io.IOException
- If the writing failed.public void writeUnsignedInt(long value) throws java.io.IOException
BitStreamWriter
writeUnsignedInt
in interface BitStreamWriter
value
- Unsigned integer value to write.java.io.IOException
- If the writing failed.public void writeLong(long v) throws java.io.IOException
BitStreamWriter
writeLong
in interface BitStreamWriter
v
- Signed integer value to write.java.io.IOException
- If the writing failed.public void writeBigInteger(java.math.BigInteger value, int numBits) throws java.io.IOException
BitStreamWriter
writeBigInteger
in interface BitStreamWriter
value
- Big integer value to write.numBits
- Number of bits for the value to write.java.io.IOException
- If the writing failed.public void writeFloat16(float value) throws java.io.IOException
BitStreamWriter
writeFloat16
in interface BitStreamWriter
value
- Half precision float value to write.java.io.IOException
- If the writing failed.public void writeFloat32(float value) throws java.io.IOException
BitStreamWriter
writeFloat32
in interface BitStreamWriter
value
- Single precision float value to write.java.io.IOException
- If the writing failed.public void writeFloat64(double value) throws java.io.IOException
BitStreamWriter
writeFloat64
in interface BitStreamWriter
value
- Double precision float value to write.java.io.IOException
- If the writing failed.public void writeBytes(byte[] value) throws java.io.IOException
BitStreamWriter
writeBytes
in interface BitStreamWriter
value
- Zserio bytes to write.java.io.IOException
- If the writing failed.public void writeString(java.lang.String value) throws java.io.IOException
BitStreamWriter
writeString
in interface BitStreamWriter
value
- Zserio string to write.java.io.IOException
- If the writing failed.public void writeBool(boolean value) throws java.io.IOException
BitStreamWriter
writeBool
in interface BitStreamWriter
value
- Boolean value to write.java.io.IOException
- If the writing failed.public void writeVarInt16(short value) throws java.io.IOException
BitStreamWriter
writeVarInt16
in interface BitStreamWriter
value
- Variable 17 bit integer value to write.java.io.IOException
- If the writing failed.public void writeVarUInt16(short value) throws java.io.IOException
BitStreamWriter
writeVarUInt16
in interface BitStreamWriter
value
- Variable 16 bit unsigned integer value to write.java.io.IOException
- If the writing failed.public void writeVarInt32(int value) throws java.io.IOException
BitStreamWriter
writeVarInt32
in interface BitStreamWriter
value
- Variable 32 bit integer value to write.java.io.IOException
- If the writing failed.public void writeVarUInt32(int value) throws java.io.IOException
BitStreamWriter
writeVarUInt32
in interface BitStreamWriter
value
- Variable 32 bit unsigned integer value to write.java.io.IOException
- If the writing failed.public void writeVarInt64(long value) throws java.io.IOException
BitStreamWriter
writeVarInt64
in interface BitStreamWriter
value
- Variable 64 bit integer value to write.java.io.IOException
- If the writing failed.public void writeVarUInt64(long value) throws java.io.IOException
BitStreamWriter
writeVarUInt64
in interface BitStreamWriter
value
- Variable 64 bit unsigned integer value to write.java.io.IOException
- If the writing failed.public void writeVarInt(long value) throws java.io.IOException
BitStreamWriter
writeVarInt
in interface BitStreamWriter
value
- Variable signed integer value to write.java.io.IOException
- If the writing failed.public void writeVarUInt(java.math.BigInteger value) throws java.io.IOException
BitStreamWriter
writeVarUInt
in interface BitStreamWriter
value
- Variable unsigned integer value to write.java.io.IOException
- If the writing failed.public void writeVarSize(int value) throws java.io.IOException
BitStreamWriter
writeVarSize
in interface BitStreamWriter
value
- Variable size integer value to write.java.io.IOException
- If the writing failed.public void writeBitBuffer(BitBuffer bitBuffer) throws java.io.IOException
BitStreamWriter
writeBitBuffer
in interface BitStreamWriter
bitBuffer
- Bit buffer to write.java.io.IOException
- If the writing failed.public void alignTo(int alignVal) throws java.io.IOException
BitStreamWriter
alignTo
in interface BitStreamWriter
alignVal
- An aligning value to use.java.io.IOException
- If the alignment failed.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public byte[] toByteArray() throws java.io.IOException
java.io.IOException
- If stream manipulation failed.public long getBitPosition()
public int getBytePosition()
public void setBitPosition(long bitPosition) throws java.io.IOException
bitPosition
- Bit position to set.java.io.IOException
- Throws in case of any error.public int getBitOffset()
protected static void checkRange(int numBits) throws java.lang.IllegalArgumentException
numBits
- Number of bits to check.java.lang.IllegalArgumentException
- If the numBits value is smaller than zero or greater than 64.protected static void checkUnsignedRange(int numBits) throws java.lang.IllegalArgumentException
numBits
- Number of bits to check.java.lang.IllegalArgumentException
- If the numBits value is smaller than zero or greater than 63.Last updated 2024-12-05 10:34:50