public class BitInputStream extends InputStream
BitOutputStream to facilitate
reading and writing data several bits-at-a-time. BitInputStream objects
that are constructed from a File support reset(). However,
if constructed from an InputStream an object cannot be reset.
Any exceptions generated are rethrown as RuntimeException objects
so client code does not have to catch or rethrow them. (Unless the extension
of InputStream requires throwing as another type of exception, e.g.,
as with method read.
| Constructor and Description |
|---|
BitInputStream(File file)
Construct a bit-at-a-time input stream from
file. |
BitInputStream(InputStream in)
Open a bit-at-a-time stream that reads from supplied InputStream.
|
BitInputStream(String filename)
Construct a bit-at-a-time input stream from a file whose
name is supplied.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the input stream.
|
boolean |
markSupported()
Return true if the stream has been initialized from a File and
is thus reset-able.
|
int |
read()
Required by classes extending InputStream, returns
the next byte from this stream as an int value.
|
int |
readBits(int howManyBits)
Returns the number of bits requested as rightmost bits in
returned value, returns -1 if not enough bits available to
satisfy the request.
|
void |
reset()
Reset stream to beginning.
|
public BitInputStream(String filename)
filename - is the name of the file that will be read.RuntimeException - if filename cannot be opened.public BitInputStream(File file)
file.file - is the File that is the source of the inputRuntimeExceptoin - if file cannot be opened.public BitInputStream(InputStream in)
in - is the stream from which bits are read.public boolean markSupported()
markSupported in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOException - if not reset-able (e.g., constructed from InputStream).public void close()
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamRuntimeException - if the close failspublic int readBits(int howManyBits)
throws IOException
howManyBits - is the number of bits to read and returnhowManyBits
are valid, returns -1 if not enough bits leftIOExceptionpublic int read()
throws IOException
read in class InputStreamIOException