コード例 #1
0
ファイル: HuffmanTree.java プロジェクト: zdavatz/elexis
 /**
  * compute a frequency table from an InputStream and save a compacted representation of this table
  * in the system preferences. (To be used later by @see #useStandardTable(String) )
  *
  * @param name name to give the table.
  * @param in InputStream
  * @return true on success
  * @throws Exception
  */
 public static boolean CreateStandardTableFromStream(String name, InputStream in)
     throws Exception {
   int[] tbl = new int[TABLESIZE];
   while (in.available() != 0) {
     int c = in.read();
     tbl[c]++;
   }
   byte[] dest = HuffmanTree.compactTable(tbl);
   Preferences pref = Preferences.userNodeForPackage(Huff.class);
   Preferences node = pref.node("StandardTables");
   node.putByteArray(name, dest);
   pref.flush();
   return true;
 }
コード例 #2
0
ファイル: HuffmanTree.java プロジェクト: zdavatz/elexis
 /**
  * Import a compaced frequency table from the system preferences (In windows from the registry
  * HKLM/JavaSoft/Prefs/ch/rgw/tools/Compress/StandardTables, in Linux from ~/.prefs)
  *
  * @param name Name of the table in the registry. If no table with this name is found, the default
  *     table (TextDeutsch) is returned.
  * @return the table
  */
 public static int[] useStandardTable(String name) {
   Preferences pr = Preferences.userNodeForPackage(Huff.class);
   Preferences node = pr.node("StandardTables");
   byte[] res = node.getByteArray(name, TextDeutsch);
   return HuffmanTree.expandTable(res);
 }