Interface BitInputStream
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Implementing Classes:
ByteBitInputStream
public interface BitInputStream extends java.io.Closeable
A stream of bits that can be read. Bits are packed in little endian within a byte. For example, the byte 0x87 reads as the sequence of bits [1,1,1,0,0,0,0,1].
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes this stream and the underlying input stream.int
getBitPosition()
Returns the current bit position, which ascends from 0 to 7 as bits are read.int
read()
Reads a bit from this stream.int
readByte()
Discards the remainder of the current byte (if any) and reads the next whole byte from the stream.int
readNoEof()
Reads a bit from this stream.
-
-
-
Method Detail
-
getBitPosition
int getBitPosition()
Returns the current bit position, which ascends from 0 to 7 as bits are read.- Returns:
- the current bit position, which is between 0 and 7
-
readByte
int readByte() throws java.io.IOException
Discards the remainder of the current byte (if any) and reads the next whole byte from the stream. Returns -1 if the end of stream is reached.- Returns:
- the next byte from the stream, or -1 if the end of stream is reached
- Throws:
java.io.IOException
-
read
int read() throws java.io.IOException
Reads a bit from this stream. Returns 0 or 1 if a bit is available, or -1 if the end of stream is reached. The end of stream always occurs on a byte boundary.- Returns:
- the next bit of 0 or 1, or -1 for the end of stream
- Throws:
java.io.IOException
- if an I/O exception occurred
-
readNoEof
int readNoEof() throws java.io.IOException
Reads a bit from this stream. Returns 0 or 1 if a bit is available, or throws anEOFException
if the end of stream is reached. The end of stream always occurs on a byte boundary.- Returns:
- the next bit of 0 or 1
- Throws:
java.io.IOException
- if an I/O exception occurredjava.io.EOFException
- if the end of stream is reached
-
close
void close() throws java.io.IOException
Closes this stream and the underlying input stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
- if an I/O exception occurred
-
-