コード例 #1
0
 @Override
 protected Void executeImpl(FileDescriptor request) {
   StringBuilder builder = new StringBuilder();
   BufferedReader br = null;
   try {
     br = new BufferedReader(new FileReader(request));
     String line;
     while ((line = br.readLine()) != null) {
       builder.append(line);
       builder.append("\n");
     }
     br.close();
     Json.JsonObject json = Json.createFromString(builder.toString()).asObject();
     loadDeviceAliases(json.asArray("device_aliases"));
     restoreProfiles(json.asArray("profiles"));
   } catch (IOException e) {
     if (br != null) {
       try {
         br.close();
       } catch (IOException e1) {
       }
     }
     throw new RuntimeException(e);
   } catch (JSONException e) {
     throw new RuntimeException(e);
   }
   return null;
 }
コード例 #2
0
 private void loadDeviceAliases(Json.JsonArray device_aliases) {
   for (int i = 0; i < device_aliases.size(); i++) {
     Json.JsonObject device = device_aliases.asObject(i);
     using(Model.class)
         .execute(
             DeviceAliasAdd.class,
             new P<String, DeviceAlias>(
                 device.asString("mac"),
                 new DeviceAlias(device.asString("alias"), device.value("icon", Integer.class))));
   }
 }
コード例 #3
0
 private void restoreProfiles(Json.JsonArray profilesJson) {
   for (int i = 0; i < profilesJson.size(); i++) {
     Json.JsonObject profile = profilesJson.asObject(i);
     using(BandwidthProfileManager.class)
         .updateOrCreate(
             new BandwidthProfile(
                 profile.asString("title"),
                 profile.asString("description"),
                 profile.value("out", Integer.class),
                 profile.value("in", Integer.class)));
   }
 }