예제 #1
0
 public static String loadDevices(Hashtable devices) {
   File cf = getConfigFile();
   if (cf == null || !cf.exists()) {
     return null;
   }
   Reader fr = null;
   LineNumberReader lnr = null;
   try {
     lnr = new LineNumberReader(fr = new FileReader(cf));
     devices.clear();
     String line = lnr.readLine();
     String selected = null;
     while (line != null) {
       if (line.startsWith(devicePrefix)) {
         DeviceInfo di = new DeviceInfo();
         di.loadFromLine(line.substring(devicePrefix.length()));
         if (di.isValid()) {
           devices.put(di.btAddress.toLowerCase(), di);
         }
       } else if (line.startsWith(selectedPrefix)) {
         selected = line.substring(selectedPrefix.length());
       } else {
         int p = line.indexOf('=');
         if (p != -1) {
           properties.put(line.substring(0, p), line.substring(p + 1));
         }
       }
       line = lnr.readLine();
     }
     return selected;
   } catch (Throwable e) {
     Logger.debug(e);
     return null;
   } finally {
     if (lnr != null) {
       try {
         lnr.close();
       } catch (IOException e) {
       }
     }
     if (fr != null) {
       try {
         fr.close();
       } catch (IOException e) {
       }
     }
   }
 }