Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String decompression (String filename) {
- BinaryIn bi = new BinaryIn(filename);
- ArbreHuffman aha = new ArbreHuffman();
- String ret = "";
- Noeud racine = aha.getRacine();
- Noeud courant = racine;
- ArrayList<Boolean> valAscii = new ArrayList<Boolean>();
- // tu va lire du ascii et pas le code dans l'arbre
- boolean enAscii=false;
- Boolean tmp;
- try {
- while (tmp = bi.readBoolean()) {
- if (enAscii) {
- valAscii.add(tmp);
- if (valAscii.size()==8) {
- Char s = laValeurEnAsciiDuBinaire(valAscii);
- aha.modification(s.getC());
- // la valeur du retour
- ret += s.getC();
- // reset
- valAscii = new ArrayList<Boolean>();
- enAscii = false;
- }
- } else {
- if (courant.get(tmp) != null) {
- // si son fils n'est pas null
- continue;
- } else {
- // si son fils est null ca veut dire
- // qu'on a le code du noeud courant
- if (courant.estNyt()) {
- enAscii = true;
- } else {
- if (courant.estFeuille()) {
- char c = courant.getValue().getC();
- aha.modification(c);
- ret += c;
- } else {
- System.err.println("error");
- }
- }
- }
- }
- }
- } catch (RuntimeException e) {
- System.err.println("EMPTY");
- }
- return ret;
- }
Add Comment
Please, Sign In to add comment