|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
assignment4.BitInputStream
public class BitInputStream
Reads bits-at-a-time where the number of bits is between 1 and 32.
Updated for version 2.0 to extend java.io.InputStream. This class
can be used together with 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 Summary | |
---|---|
BitInputStream(java.io.File file)
Construct a bit-at-a-time input stream from file . |
|
BitInputStream(java.io.InputStream in)
Open a bit-at-a-time stream that reads from supplied InputStream. |
|
BitInputStream(java.lang.String filename)
Construct a bit-at-a-time input stream from a file whose name is supplied. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.io.InputStream |
---|
available, mark, read, read, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BitInputStream(java.lang.String filename)
filename
- is the name of the file that will be read.
java.lang.RuntimeException
- if filename cannot be opened.public BitInputStream(java.io.File file)
file
.
file
- is the File that is the source of the input
RuntimeExceptoin
- if file cannot be opened.public BitInputStream(java.io.InputStream in)
in
- is the stream from which bits are read.Method Detail |
---|
public boolean markSupported()
markSupported
in class java.io.InputStream
public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
- if not reset-able (e.g., constructed from InputStream).public void close()
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.lang.RuntimeException
- if the close failspublic int readBits(int howManyBits) throws java.io.IOException
howManyBits
- is the number of bits to read and return
howManyBits
are valid, returns -1 if not enough bits left
java.io.IOException
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |