Turning strings into bits...help
I am working on a Huffman coding application that reads the frequencies of all the bytes in the file, then builds a Huffman tree and creates codes for each byte value, depending on their frequency.
Now I have an array named codeTable containing 256 Strings for each 256 possible frequencies.
The codes in codeTable look like this:
Now I need to output those codes to an BufferedStreamOuput. I need to find an efficient way to put those strings in the output file.
Each 1 and 0's should be 1 BIT long, therefore byte codeString = code.getBytes(); will not do the trick as it makes each 1 and 0 a byte long...thus making the output file bigger than the input(against the purpose of my application).
So what i need to figure out is a way to pack 1010101010 so i can write them out.
BufferedOuputStream as 2 write() methods, 1 that takes an int as parameter and the other takes a byte array.....