예제 #1
0
  public void save() {
    String json = Utils.getGson().toJson(this);

    try {
      FileUtils.writeStringToFile(usersFile, json, Charset.forName("UTF-8"));
    } catch (IOException e) {
      Utils.getLogger().log(Level.WARNING, "Unable to save users " + usersFile);
    }
  }
예제 #2
0
  public static Users load() {
    File userFile = new File(Utils.getSettingsDirectory(), "users.json");
    if (!userFile.exists()) {
      Utils.getLogger()
          .log(
              Level.WARNING,
              "Unable to load users from " + userFile + " because it does not exist.");
      return new Users(userFile);
    }

    try {
      String json = FileUtils.readFileToString(userFile, Charset.forName("UTF-8"));
      Users newModel = Utils.getGson().fromJson(json, Users.class);
      newModel.setUserFile(userFile);
      return newModel;
    } catch (JsonSyntaxException e) {
      Utils.getLogger().log(Level.WARNING, "Unable to load users from " + userFile);
    } catch (IOException e) {
      Utils.getLogger().log(Level.WARNING, "Unable to load users from " + userFile);
    }

    return new Users(userFile);
  }