AccountStore.java (1224B)
1 package eu.siacs; 2 3 import rocks.xmpp.addr.Jid; 4 5 import java.io.*; 6 import java.util.Properties; 7 8 public class AccountStore { 9 10 private static final File FILE = new File("accounts.xml"); 11 12 public static String getPassword(Jid jid) { 13 Properties properties = new Properties(); 14 try { 15 properties.loadFromXML(new FileInputStream(FILE)); 16 return properties.getProperty(jid.asBareJid().toString()); 17 } catch (IOException e) { 18 return null; 19 } 20 } 21 22 public static boolean storePassword(Jid jid, String password) { 23 Properties properties = new Properties(); 24 try { 25 properties.loadFromXML(new FileInputStream(FILE)); 26 } catch (FileNotFoundException e) { 27 try { 28 FILE.createNewFile(); 29 } catch (IOException e1) { 30 // 31 } 32 } catch (IOException e) { 33 //ignored 34 } 35 properties.put(jid.asBareJid().toString(),password); 36 try { 37 properties.storeToXML(new FileOutputStream(FILE),null); 38 return true; 39 } catch (IOException e) { 40 e.printStackTrace(); 41 return false; 42 } 43 } 44 45 }