Guest User

Untitled

a guest
Apr 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1.     public static String decompression (String filename) {
  2.         BinaryIn bi = new BinaryIn(filename);
  3.         ArbreHuffman aha = new ArbreHuffman();
  4.         String ret = "";
  5.         Noeud racine = aha.getRacine();
  6.        
  7.         Noeud courant = racine;
  8.        
  9.         ArrayList<Boolean> valAscii = new ArrayList<Boolean>();
  10.         // tu va lire du ascii et pas le code dans l'arbre
  11.         boolean enAscii=false;
  12.         Boolean tmp;
  13.        
  14.         try {
  15.             while (tmp = bi.readBoolean()) {
  16.                 if (enAscii) {
  17.                     valAscii.add(tmp);
  18.                     if (valAscii.size()==8) {
  19.                         Char s = laValeurEnAsciiDuBinaire(valAscii);
  20.                         aha.modification(s.getC());
  21.                        
  22.                         // la valeur du retour
  23.                         ret += s.getC();
  24.                        
  25.                         // reset
  26.                         valAscii = new ArrayList<Boolean>();
  27.                         enAscii = false;
  28.                     }
  29.                 } else {
  30.                     if (courant.get(tmp) != null) {
  31.                         // si son fils n'est pas null
  32.                         continue;
  33.                     } else {
  34.                         // si son fils est null ca veut dire
  35.                         // qu'on a le code du noeud courant
  36.                         if (courant.estNyt()) {
  37.                             enAscii = true;
  38.                         } else {
  39.                             if (courant.estFeuille()) {
  40.                                 char c = courant.getValue().getC();
  41.                                 aha.modification(c);
  42.                                 ret += c;
  43.                             } else {
  44.                                 System.err.println("error");
  45.                             }
  46.                         }
  47.                     }
  48.                 }  
  49.             }
  50.         } catch (RuntimeException e) {
  51.             System.err.println("EMPTY");
  52.         }
  53.         return ret;
  54.     }
Add Comment
Please, Sign In to add comment