Skip to content

Binary Huffman Coding

Anthony Christe edited this page Dec 3, 2013 · 12 revisions

Reading in Binary Files

int read(byte[] b)
  • 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
int read()
  • 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).

Finding an integer from 4 bytes

The Universal Way - Bit Shifting
The Java Way - ByteBuffer

Reading Bits

BitReader Object
Querying Specific Bits

Receiving the tree

Decoding the Message

Writing Result File

Padding with Zeros

Debugging

Printing a byte a string

Clone this wiki locally