-
- All Superinterfaces:
AutoCloseable
,Closeable
,Flushable
- All Known Implementing Classes:
BitOutputAdapter
public interface BitOutput extends Flushable, Closeable
An interface for writing values of an arbitrary number of bits.- Author:
- Jin Kwon <jinahya_at_gmail.com>
- See Also:
BitInput
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default long
align()
Aligns to a single byte by padding zero bits.long
align(int bytes)
Aligns to specified number of bytes by padding zero bits.default void
close()
Closes this output and releases any system resources associated with it.default void
flush()
Flushes this output by writing any buffered output to the underlying output.default void
skip(int bits)
Skips specified number of bits by padding zero bits.default void
writeBoolean(boolean value)
Writes specified1
-bitboolean
value.default void
writeByte(boolean unsigned, int size, byte value)
Writes specifiedbyte
value of specified number of bits.default void
writeByte(int size, byte value)
Writes specified signedbyte
value of specified number of bits.default void
writeByte8(byte value)
Writes specified 8-bit signedbyte
value.default void
writeChar(int size, char value)
Writes specifiedchar
value of specified bit size.default void
writeChar16(char value)
Writes specified 16-bitchar
value.default void
writeDouble64(double value)
Writes specified 64-bitdouble
value.default void
writeFloat32(float value)
Writes specified 32-bitfloat
value.void
writeInt(boolean unsigned, int size, int value)
Writes specifiedint
value of specified number of bits.default void
writeInt(int size, int value)
Writes specified signedint
value of specified bit size.default void
writeInt32(int value)
Writes specified 32-bit signed value.default void
writeInt32Le(int value)
Deprecated.Reverse specified value's bytes usingInteger.reverseBytes(int)
and write the result withwriteInt32(int)
method.default void
writeLong(boolean unsigned, int size, long value)
Writes specifiedlong
value of specified number of bits.default void
writeLong(int size, long value)
Writes specified signedlong
value of specified bit size.default void
writeLong64(long value)
Writes specified 64-bit signedlong
value.default void
writeLong64Le(long value)
Deprecated.Reverse specified value's bytes usingLong.reverseBytes(long)
method and write the result withwriteLong64(long)
method.default void
writeShort(boolean unsigned, int size, short value)
Writes specifiedshort
value of specified number of bits.default void
writeShort(int size, short value)
Writes specified signedshort
value of specified number of bits.default void
writeShort16(short value)
Writes specified 16-bit signedshort
value.default void
writeShort16Le(short value)
Deprecated.Reverse specified value's bytes withShort.reverseBytes(short)
method and writes the result withwriteShort16(short)
method.default void
writeUnsignedByte(int size, byte value)
Writes specified unsignedbyte
value of specified bit size.default void
writeUnsignedInt(int size, int value)
Writes specified unsignedint
value of specified bit size.default void
writeUnsignedLong(int size, long value)
Writes specified unsignedlong
value of specified bit size.default void
writeUnsignedShort(int size, short value)
Writes specified unsignedshort
value of specified bit size.default <T> void
writeValue(ValueAdapter<? super T> adapter, T value)
Writes specified value using specified adapter.
-
-
-
Method Detail
-
flush
default void flush() throws IOException
Flushes this output by writing any buffered output to the underlying output. Theflush()
method ofBitOutput
interface does nothing.- Specified by:
flush
in interfaceFlushable
- Throws:
IOException
- if an I/O error occurs.
-
close
default void close() throws IOException
Closes this output and releases any system resources associated with it. Theclose
method ofBitOutput
interface does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurs.
-
writeBoolean
default void writeBoolean(boolean value) throws IOException
Writes specified1
-bitboolean
value. This method writes0b1
fortrue
and0b0
forfalse
.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeByte
default void writeByte(boolean unsigned, int size, byte value) throws IOException
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.
-
writeByte
default void writeByte(int size, byte value) throws IOException
Writes specified signedbyte
value of specified number of bits.- Parameters:
size
- the number of bits to write; between1
and 8, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeByte8
default void writeByte8(byte value) throws IOException
Writes specified 8-bit signedbyte
value.- Parameters:
value
- the 8-bit signedbyte
value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeUnsignedByte
default void writeUnsignedByte(int size, byte value) throws IOException
Writes specified unsignedbyte
value of specified bit size.- Parameters:
size
- the number of lower bits to write; between1
(inclusive) and 8 (exclusive).value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeShort
default void writeShort(boolean unsigned, int size, short value) throws IOException
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.
-
writeShort
default void writeShort(int size, short value) throws IOException
Writes specified signedshort
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.
-
writeShort16
default void writeShort16(short value) throws IOException
Writes specified 16-bit signedshort
value.- Parameters:
value
- the 16-bit signedshort
value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
writeShort(int, short)
-
writeShort16Le
@Deprecated default void writeShort16Le(short value) throws IOException
Deprecated.Reverse specified value's bytes withShort.reverseBytes(short)
method and writes the result withwriteShort16(short)
method.Writes specified 16-bit signedshort
value in little endian byte order.- Parameters:
value
- the 16-bit signedshort
value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeUnsignedShort
default void writeUnsignedShort(int size, short value) throws IOException
Writes specified unsignedshort
value of specified bit size.- Parameters:
size
- the number of bits to write; between1
(inclusive) and 16 (exclusive).value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeInt
void writeInt(boolean unsigned, int size, int value) throws IOException
Writes specifiedint
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 (32 - (unsigned ? 1 : 0
)), both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeInt
default void writeInt(int size, int value) throws IOException
Writes specified signedint
value of specified bit size.- Parameters:
size
- the number of bits to write; between1
and 32, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeInt32
default void writeInt32(int value) throws IOException
Writes specified 32-bit signed value.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeInt32Le
@Deprecated default void writeInt32Le(int value) throws IOException
Deprecated.Reverse specified value's bytes usingInteger.reverseBytes(int)
and write the result withwriteInt32(int)
method.Writes specified 32-bit signedint
value in little endian byte order.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeUnsignedInt
default void writeUnsignedInt(int size, int value) throws IOException
Writes specified unsignedint
value of specified bit size.- Parameters:
size
- the number of bits to write; between1
(inclusive) and 32 (exclusive).value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeLong
default void writeLong(boolean unsigned, int size, long value) throws IOException
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.
-
writeLong
default void writeLong(int size, long value) throws IOException
Writes specified signedlong
value of specified bit size.- Parameters:
size
- the number of bits to write; between1
and 64, both inclusive.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeLong64
default void writeLong64(long value) throws IOException
Writes specified 64-bit signedlong
value.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeLong64Le
@Deprecated default void writeLong64Le(long value) throws IOException
Deprecated.Reverse specified value's bytes usingLong.reverseBytes(long)
method and write the result withwriteLong64(long)
method.Writes specified 64-bit signedlong
value in little endian byte order.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeUnsignedLong
default void writeUnsignedLong(int size, long value) throws IOException
Writes specified unsignedlong
value of specified bit size.- Parameters:
size
- the number of bits to write; between1
(inclusive) and 64 (exclusive).value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
writeChar
default void writeChar(int size, char value) throws IOException
Writes specifiedchar
value of specified bit size.- 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.- See Also:
writeChar16(char)
-
writeChar16
default void writeChar16(char value) throws IOException
Writes specified 16-bitchar
value.- Parameters:
value
- the value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
writeChar(int, char)
-
writeFloat32
default void writeFloat32(float value) throws IOException
Writes specified 32-bitfloat
value. ThewriteFloat32(float)
method ofBitOutput
interface writes specified value as a 32-bitint
value converted withFloat.floatToRawIntBits(float)
method.- Parameters:
value
- thefloat
value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
Float.floatToRawIntBits(float)
,writeInt32(int)
-
writeDouble64
default void writeDouble64(double value) throws IOException
Writes specified 64-bitdouble
value. ThewriteDouble64(double)
method ofBitOutput
interface writes specified value as a 64-bitlong
value converted withDouble.doubleToRawLongBits(double)
method.- Parameters:
value
- thedouble
value to write.- Throws:
IOException
- if an I/O error occurs.- See Also:
Double.doubleToRawLongBits(double)
,writeLong64(long)
-
writeValue
default <T> void writeValue(ValueAdapter<? super T> adapter, T value) throws IOException
Writes specified value using specified adapter. ThewriteValue(ValueAdapter, T)
method ofBitOutput
interface invokesValueWriter.write(BitOutput, Object)
withthis
and specified value.- Type Parameters:
T
- value type parameter- Parameters:
adapter
- the adapter.value
- the value to write.- Throws:
IOException
- if an I/O error occurs.
-
skip
default void skip(int bits) throws IOException
Skips specified number of bits by padding zero bits.- Parameters:
bits
- the number of bit to skip; must be positive.- Throws:
IllegalArgumentException
- ifbits
is not positive.IOException
- if an I/O error occurs.
-
align
long align(int bytes) throws IOException
Aligns to specified number of bytes by padding zero bits.- Parameters:
bytes
- the number of bytes to align; must be positive.- Returns:
- the number of bits padded while aligning.
- Throws:
IllegalArgumentException
- ifbytes
is not positive.IOException
- if an I/O error occurs.
-
align
default long align() throws IOException
Aligns to a single byte by padding zero bits. Thealign()
method ofBitOutput
interface invokesalign(int)
with 1.- Returns:
- the number of bits padded while aligning.
- Throws:
IOException
- if an I/O error occurs.- See Also:
align(int)
-
-