Implement a class HuffmanIso
that extends Huffman
.
In such class, override the methods writeTrie
and readTrie
.
When writing/reading a char for a given leaf node, use the charset ISO-8859-1 instead
of the current UTF-16 in Huffman
.
Note 0: you would lose Unicode support by doing it.
Note 1: for coding/decoding, you can use the method getBytes
in String
with
charset StandardCharsets.ISO_8859_1
.
Write a test class HuffmanIsoTest
with the following two tests:
-
testCompareOnShortNorwegianSentence
in which you compare bothHuffmanIso
andHuffman
on the text string "Jeg ønsker å få en god karakter i denne eksamenen" encoded in UTF-8. Verify thatHuffmanIso
can compress it, whereasHuffman
actually makes it bigger. Explain why. -
testCompareOnBook
in which you compare bothHuffmanIso
andHuffman
on the text of the Odyssey book encoded in UTF-8. Verify that bothHuffmanIso
andHuffman
do compress it, but their difference in compression ratio is minimal (i.e., less than 0.001). Explain why.
Solutions to this exercise can be found in the solutions
module, under the org.pg4200.sol12
package.