-
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
BitInputAdapter
public interface BitInput extends Closeable
An interface for reading values of an arbitrary number of bits.- Author:
- Jin Kwon <jinahya_at_gmail.com>
- See Also:
BitOutput
-
-
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 discarding bits.long
align(int bytes)
Aligns to specified number of bytes by discarding bits.default void
close()
Closes this input and releases any system resources associated with it.default boolean
readBoolean()
Reads a1
-bitboolean
value.default byte
readByte(boolean unsigned, int size)
Reads abyte
value of specified number of bits.default byte
readByte(int size)
Reads a signedbyte
value of specified number of bits.default byte
readByte8()
Reads a 8-bit signedbyte
value.default char
readChar(int size)
Reads achar
value of specified bit size.default char
readChar16()
Reads a 16-bitchar
value.default double
readDouble64()
Reads a 64-bitdouble
value.default float
readFloat32()
Reads a 32-bitfloat
value.int
readInt(boolean unsigned, int size)
Reads anint
value of specified number of bits.default int
readInt(int size)
Reads a signedint
value of specified bit size.default int
readInt32()
Reads a 32-bit signedint
value.default int
readInt32Le()
Deprecated.Reads a value withreadInt32()
method and reverse bytes withInteger.reverseBytes(int)
method.default long
readLong(boolean unsigned, int size)
Reads along
value of specified number of bits.default long
readLong(int size)
Reads a signedlong
value of specified bit size.default long
readLong64()
Reads a 64-bit signedlong
value.default long
readLong64Le()
Deprecated.Reads a value withreadLong64()
and reverse bytes withLong.reverseBytes(long)
method.default short
readShort(boolean unsigned, int size)
Reads ashort
value of specified number of bits.default short
readShort(int size)
Reads a signedshort
value of specified number of bits.default short
readShort16()
Reads a 16-bit signedshort
value.default short
readShort16Le()
Deprecated.Reads a value withreadShort16()
and reverse bytes withShort.reverseBytes(short)
method.default byte
readUnsignedByte(int size)
Reads an unsignedbyte
value of specified number of bits.default int
readUnsignedInt(int size)
Reads an unsignedint
value of specified bit size.default long
readUnsignedLong(int size)
Reads an unsignedlong
value of specified bit size.default short
readUnsignedShort(int size)
Reads an unsignedshort
value of specified number of bits.default <T> T
readValue(ValueAdapter<? extends T> adapter)
Reads a value using specified adapter.default void
skip(int bits)
Skips specified number of bits by discarding bits.
-
-
-
Method Detail
-
close
default void close() throws IOException
Closes this input and releases any system resources associated with it. Theclose
method ofBitInput
interface does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurs.
-
readBoolean
default boolean readBoolean() throws IOException
Reads a1
-bitboolean
value. This method reads a1
-bit unsignedint
value and returnstrue
for0b1
andfalse
for0b0
.- Returns:
- the value read.
- Throws:
IOException
- if an I/O error occurs.
-
readByte
default byte readByte(boolean unsigned, int size) throws IOException
Reads abyte
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 read; between1
and (8 - (unsigned ? 1 : 0
)), both inclusive.- Returns:
- a
byte
value of specified bitsize
. - Throws:
IOException
- if an I/O error occurs.
-
readByte
default byte readByte(int size) throws IOException
Reads a signedbyte
value of specified number of bits.- Parameters:
size
- the number of bits to read; between1
and 8, both inclusive.- Returns:
- a signed
byte
value of specified bitsize
. - Throws:
IOException
- if an I/O error occurs.
-
readByte8
default byte readByte8() throws IOException
Reads a 8-bit signedbyte
value.- Returns:
- a signed 8-bit
byte
value. - Throws:
IOException
- if an I/O error occurs.
-
readUnsignedByte
default byte readUnsignedByte(int size) throws IOException
Reads an unsignedbyte
value of specified number of bits.- Parameters:
size
- the number of bits to read; between1
(inclusive) and 8 (exclusive).- Returns:
- an unsigned
byte
value of specified bitsize
. - Throws:
IOException
- if an I/O error occurs.
-
readShort
default short readShort(boolean unsigned, int size) throws IOException
Reads ashort
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 read; between1
and (16 - (unsigned ?1
:0
)), both inclusive.- Returns:
- a
short
value of specifiedsize
. - Throws:
IOException
- if an I/O error occurs.
-
readShort
default short readShort(int size) throws IOException
Reads a signedshort
value of specified number of bits.- Parameters:
size
- the number of bits to read; between1
and 16, both inclusive.- Returns:
- a signed
short
value of specified bitsize
. - Throws:
IOException
- if an I/O error occurs.
-
readShort16
default short readShort16() throws IOException
Reads a 16-bit signedshort
value.- Returns:
- a 16-bit signed
short
value read. - Throws:
IOException
- if an I/O error occurs.- See Also:
readShort(int)
-
readShort16Le
@Deprecated default short readShort16Le() throws IOException
Deprecated.Reads a value withreadShort16()
and reverse bytes withShort.reverseBytes(short)
method.Reads a 16-bit signedshort
value in little endian byte order.- Returns:
- a 16-bit signed
short
value read in little endian byte order. - Throws:
IOException
- if an I/O error occurs.
-
readUnsignedShort
default short readUnsignedShort(int size) throws IOException
Reads an unsignedshort
value of specified number of bits.- Parameters:
size
- the number of bits to read; between1
(inclusive) and 16 (exclusive).- Returns:
- an unsigned
short
value of specified bitsize
. - Throws:
IOException
- if an I/O error occurs.
-
readInt
int readInt(boolean unsigned, int size) throws IOException
Reads anint
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 read; between1
and (32 - (unsigned ? 1: 0
)), both inclusive.- Returns:
- an
int
value of specifiedsize
. - Throws:
IOException
- if an I/O error occurs.
-
readInt
default int readInt(int size) throws IOException
Reads a signedint
value of specified bit size.- Parameters:
size
- the number of bits to read; between1
and 32, both inclusive.- Returns:
- a signed
int
value. - Throws:
IOException
- if an I/O error occurs.
-
readInt32
default int readInt32() throws IOException
Reads a 32-bit signedint
value.- Returns:
- a 32-bit signed
int
value read. - Throws:
IOException
- if an I/O error occurs.
-
readInt32Le
@Deprecated default int readInt32Le() throws IOException
Deprecated.Reads a value withreadInt32()
method and reverse bytes withInteger.reverseBytes(int)
method.Reads a 32-bit signedint
value in little endian byte order.- Returns:
- a 32-bit signed
int
value. - Throws:
IOException
- if an I/O error occurs.
-
readUnsignedInt
default int readUnsignedInt(int size) throws IOException
Reads an unsignedint
value of specified bit size.- Parameters:
size
- the number of bits to read; between1
(inclusive) and 32 (exclusive).- Returns:
- an unsigned
int
value. - Throws:
IOException
- if an error occurs.
-
readLong
default long readLong(boolean unsigned, int size) throws IOException
Reads along
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 read; between1
and (64 - (unsigned ? 1: 0
)), both inclusive.- Returns:
- a
long
value of specified bit size. - Throws:
IOException
- if an I/O error occurs.
-
readLong
default long readLong(int size) throws IOException
Reads a signedlong
value of specified bit size.- Parameters:
size
- the number of bits to read; between1
and 64, both inclusive.- Returns:
- a signed
long
value. - Throws:
IOException
- if an I/O error occurs.
-
readLong64
default long readLong64() throws IOException
Reads a 64-bit signedlong
value.- Returns:
- a 64-bit signed
long
value. - Throws:
IOException
- if an I/O error occurs.
-
readLong64Le
@Deprecated default long readLong64Le() throws IOException
Deprecated.Reads a value withreadLong64()
and reverse bytes withLong.reverseBytes(long)
method.Reads a 64-bit signedlong
value in little endian byte order.- Returns:
- a 64-bit signed
long
value read. - Throws:
IOException
- if an I/O error occurs.
-
readUnsignedLong
default long readUnsignedLong(int size) throws IOException
Reads an unsignedlong
value of specified bit size.- Parameters:
size
- the number of bits to read; between1
(inclusive) and 64 (exclusive).- Returns:
- an unsigned
long
value. - Throws:
IOException
- if an error occurs.
-
readChar
default char readChar(int size) throws IOException
Reads achar
value of specified bit size.- Parameters:
size
- the number of bits to read; between1
and 16, both inclusive.- Returns:
- a
char
value. - Throws:
IOException
- if an I/O error occurs.- See Also:
readChar16()
-
readChar16
default char readChar16() throws IOException
Reads a 16-bitchar
value.- Returns:
- a
char
value. - Throws:
IOException
- if an I/O error occurs.- See Also:
readChar(int)
-
readFloat32
default float readFloat32() throws IOException
Reads a 32-bitfloat
value. ThereadFloat32()
method ofBitInput
interface reads a 32-bitint
value and returns afloat
value converted withFloat.intBitsToFloat(int)
method.- Returns:
- a 32-bit
float
value - Throws:
IOException
- if an I/O error occurs.- See Also:
Float.intBitsToFloat(int)
-
readDouble64
default double readDouble64() throws IOException
Reads a 64-bitdouble
value. ThereadDouble64()
method ofBitInput
interface reads a 64-bitlong
value and returns adouble
value converted withDouble.longBitsToDouble(long)
method.- Returns:
- a 64-bit
double
value - Throws:
IOException
- if an I/O error occurs.- See Also:
Double.longBitsToDouble(long)
-
readValue
default <T> T readValue(ValueAdapter<? extends T> adapter) throws IOException
Reads a value using specified adapter. ThereadValue(ValueAdapter)
method ofBitInput
interface invokesValueReader.read(BitInput)
method withthis
.- Type Parameters:
T
- value type parameter- Parameters:
adapter
- the adapter.- Returns:
- a value read.
- Throws:
IOException
- if an I/O error occurs.
-
skip
default void skip(int bits) throws IOException
Skips specified number of bits by discarding 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 discarding bits.- Parameters:
bytes
- the number of bytes to align; must be positive.- Returns:
- the number of bits discarded 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 discarding bits. Thealign()
method ofBitInput
interface invokesalign(int)
with 1.- Returns:
- the number of bits discarded while aligning.
- Throws:
IOException
- if an I/O error occurs.- See Also:
align(int)
-
-