Package com.github.jinahya.bit.io
Interface BitOutput
- All Known Implementing Classes:
ByteOutputAdapter
public interface BitOutput
An interface for writing values of arbitrary number of bits.
- Author:
- Jin Kwon <jinahya_at_gmail.com>
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionlong
align
(int bytes) Aligns to specified number of bytes by padding required number of zero-bits.void
reset()
Resets the total number of bytes written so far to0
.default void
skip
(int bits) Writes specified number of zero-bits.default void
writeBoolean
(boolean value) Writes specifiedboolean
value.default void
writeByte
(boolean unsigned, int size, byte value) Writes specifiedbyte
value of specified number of bits.default void
writeChar
(int size, char value) Writes specifiedchar
value of specified number of bits.default void
writeDouble
(int exponentSize, int significandSize, double value) Writes specifiedfloat
value with specifiedexponent
size andsignificand
size.default void
writeFloat
(int exponentSize, int significandSize, float value) Writes specifiedfloat
value with specifiedexponent
size andsignificand
size.void
writeInt
(boolean unsigned, int size, int value) Writes specifiedint
value of specified number of bits.default void
writeLong
(boolean unsigned, int size, long value) Writes specifiedlong
value of specified number of bits.default <T> void
writeObject
(BitWriter<? super T> writer, T value) Writes specified value using specified writer.default void
writeShort
(boolean unsigned, int size, short value) Writes specifiedshort
value of specified number of bits.
-
Method Details
-
writeBoolean
Writes specifiedboolean
value.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- Implementation Requirements:
- The default implementation writes a
1
-bit unsignedint
value(0b1
fortrue
,0b0
forfalse
) for thevalue
.
-
writeByte
Writes specifiedbyte
value of specified number of bits.- Parameters:
unsigned
- a flag for indicating unsigned value;true
for unsigned,false
for signed.size
- the number of bits to write; between1
and (8 - (unsigned ? 1: 0
)), both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- Implementation Requirements:
- The default implementation invokes
writeInt(boolean, int, int)
with given arguments.
-
writeShort
Writes specifiedshort
value of specified number of bits.- Parameters:
unsigned
- a flag for indicating unsigned value;true
for unsigned,false
for signed.size
- the number of bits to write; between1
and (16 - (unsigned ? 1 : 0
)), both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- Implementation Requirements:
- The default implementation invokes
writeInt(boolean, int, int)
method with given arguments.
-
writeInt
Writes specifiedint
value of specified number of bits.- Parameters:
unsigned
- a flag for indicating an unsigned value;true
for unsigned,false
for signed.size
- the number of bits to write; between1
and (32 - (unsigned ? 1 : 0
)), both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeLong
Writes specifiedlong
value of specified number of bits.- Parameters:
unsigned
- a flag for indicating unsigned value;true
for unsigned,false
for signed.size
- the number of bits to write; between1
and (64 - (unsigned ? 1 : 0
)), both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeChar
Writes specifiedchar
value of specified number of bits.- Parameters:
size
- the number of bits to write; between1
and 16, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- Implementation Requirements:
- The default implementation invokes
writeInt(boolean, int, int)
method with given arguments.
-
writeFloat
Writes specifiedfloat
value with specifiedexponent
size andsignificand
size.- Parameters:
exponentSize
- the number of lower exponent bits to write; between 1 and 8, both inclusive.significandSize
- the number of left-most significand bits to write; between 1 and 23, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
-
writeDouble
Writes specifiedfloat
value with specifiedexponent
size andsignificand
size.- Parameters:
exponentSize
- the number of lower exponent bits to write; between 1 and 11, both inclusive.significandSize
- the number of left-most significand bits to write; between 1 and 52, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
-
writeObject
Writes specified value using specified writer.- Type Parameters:
T
- value type parameter- Parameters:
writer
- the writer.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- Implementation Requirements:
- The default implementation invokes
BitWriter.write(BitOutput, Object)
method onwriter
withthis
andvalue
.
-
skip
Writes specified number of zero-bits.- Parameters:
bits
- the number of zero bits to write; must be positive.- Throws:
IllegalArgumentException
- ifbits
is not positive.IOException
- if an I/O error occurs.- See Also:
-
align
Aligns to specified number of bytes by padding required number of zero-bits.- Parameters:
bytes
- the number of bytes to align; must be positive.- Returns:
- the number of zero-bits padded while aligning; non-negative, always.
- Throws:
IllegalArgumentException
- ifbytes
is not positive.IOException
- if an I/O error occurs.
-
reset
void reset()Resets the total number of bytes written so far to0
.- Throws:
IllegalStateException
- if this input is notaligned
.
-