-
Notifications
You must be signed in to change notification settings - Fork 4
Binary Huffman Coding
Anthony Christe edited this page Dec 3, 2013
·
12 revisions
- Create an instance of a FileInputStream with the file name passed into constructor
- Pass the FileInputStream to the constructor of the BufferedInputStream
- Attempts to read b.length bytes into b
- Returns total number of bytes read or -1 if nothing was read
- Need to know size of file beforehand
- Useful in current assignment to read in first 4 bytes
- Reads the next byte from the stream
- Returns the byte value or -1 if the end of the stream has been reached
- Easiest to set up a while loop and continually byte for -1 (similar to BufferedReader example in lab, except we're now checking for -1 instead of null).
- ByteBuffer API
- [ByteBuffer.wrap(byte[] array)](http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#wrap(byte[]\)) - Returns an instance of a ByteBuffer given an array of bytes
- [ByteBuffer.getInt()](http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#getInt(\)) - Returns the integer value of an instance of a ByteBuffer