Пример #1
0
 public static void saveHashes(String path, HashMap<String, String> hashes) {
   if (path.equalsIgnoreCase("")) {
     MLog.e("Can't save Hashes to not given file.");
     return;
   }
   File iFile = new File(path);
   FileOutputStream fos = null;
   ObjectOutputStream oos = null;
   if (!iFile.exists()) {
     MLog.e("Can't save Hashes to not existing file: " + path);
     return;
   }
   if (hashes == null) MLog.w("Writing 'null' to hash database means clearing.");
   try {
     fos = new FileOutputStream(iFile);
     oos = new ObjectOutputStream(fos);
   } catch (FileNotFoundException fnfex) {
     MLog.e("Can't save Hashes to not existing file: " + path);
     return;
   } catch (IOException ioex) {
     MLog.e("Can't create ObjectOutputStream while saving Hashes from " + path);
     return;
   }
   try {
     oos.writeObject(hashes);
   } catch (IOException ioex) {
     MLog.e("Error writing Stream in file: " + path);
     return;
   } // catch (ClassNotFoundException cnfex) { MLog.e("Error writing Stream in file
     // (ClassNotFoundException): " + path); return; }
   MLog.d("Saved Hashmap successfully");
   return;
 }
Пример #2
0
 public static HashMap<String, String> loadHashes(String path) {
   if (path.equalsIgnoreCase("")) {
     MLog.e("Can't load Hases from not given file");
     return null;
   }
   File iFile = new File(path);
   FileInputStream fis = null;
   ObjectInputStream ois = null;
   if (!iFile.exists()) {
     MLog.e("Can't load Hashes from not existing file: " + path);
     return null;
   }
   try {
     fis = new FileInputStream(iFile);
     ois = new ObjectInputStream(fis);
   } catch (FileNotFoundException fnfex) {
     MLog.e("Can't load Hashes from not existing file: " + path);
     return null;
   } catch (EOFException eofex) {
     HashMap<String, String> tres = new HashMap<String, String>();
     saveHashes(path, tres);
     return tres;
   } catch (IOException ioex) {
     MLog.e("Can't create ObjectInputStream while loading Hashes from " + path);
     ioex.printStackTrace();
     return null;
   }
   Object o = null;
   try {
     o = ois.readObject();
   } catch (IOException ioex) {
     MLog.e("Error reading Stream in file: " + path);
     return null;
   } catch (ClassNotFoundException cnfex) {
     MLog.e("Error reading Stream in file (ClassNotFoundException): " + path);
     return null;
   }
   if (!(o instanceof HashMap)) {
     MLog.e("Invalid hash file at: " + path);
     return null;
   }
   MLog.d("Loaded Hashmap successfully");
   return (HashMap<String, String>) o;
 }