<commit_before>package pt.davidafsilva.ghn.service.options;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import pt.davidafsilva.ghn.ApplicationOptions;

/**
 * @author david
 */
public class ApplicationOptionsService {

  private static final Logger LOGGER = Logger.getLogger(ApplicationOptionsService.class.getName());
  private static final String HOME = System.getenv("user.home");
  private static final String COMMENT = "GHN Hub configuration";

  private final ApplicationOptions options;

  {
    final Properties p = new Properties();
    try {
      final Path configFile = getFileLocation();
      if (Files.exists(configFile)) {
        p.load(ApplicationOptions.class.getResourceAsStream(configFile.toString()));
      }
    } catch (final IOException e) {
      LOGGER.log(Level.WARNING, "unable to read application properties: " + e.getMessage());
    }
    options = new ApplicationOptions(p);
  }

  public ApplicationOptions getOptions() {
    return options;
  }

  public boolean save(final ApplicationOptions options) {
    try {
      final Path configFile = getFileLocation();
      options.getProperties()
          .store(new BufferedWriter(new FileWriter(configFile.toFile())), COMMENT);
      return true;
    } catch (final IOException e) {
      LOGGER.log(Level.WARNING, "unable to save application properties");
    }

    return false;
  }

  private Path getFileLocation() {
    return Paths.get(HOME, ".ghnc").toAbsolutePath();
  }
}<commit_msg>fixed save of app options<commit_after>package pt.davidafsilva.ghn.service.options;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import pt.davidafsilva.ghn.ApplicationOptions;

/**
 * @author david
 */
public class ApplicationOptionsService {

  private static final Logger LOGGER = Logger.getLogger(ApplicationOptionsService.class.getName());
  private static final String HOME = System.getProperty("user.home");
  private static final String COMMENT = "GHN Hub configuration";

  private final ApplicationOptions options;

  {
    final Properties p = new Properties();
    try {
      final Path configFile = getFileLocation();
      if (Files.exists(configFile)) {
        p.load(Files.newInputStream(configFile));
      }
    } catch (final IOException e) {
      LOGGER.log(Level.WARNING, "unable to read application properties: " + e.getMessage());
    }
    options = new ApplicationOptions(p);
  }

  public ApplicationOptions getOptions() {
    return options;
  }

  public void save(final ApplicationOptions options) {
    try {
      final Path configFile = getFileLocation();
      options.getProperties().store(Files.newOutputStream(configFile), COMMENT);
    } catch (final IOException e) {
      LOGGER.log(Level.WARNING, "unable to save application properties");
    }
  }

  private Path getFileLocation() {
    return Paths.get(HOME, ".ghnc").toAbsolutePath();
  }
}
{'fraction_non_alphanumeric': 0.10905730129390019, 'fraction_numerical': 0.0, 'mean_word_length': 3.8974358974358974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2565012', 'n_tokens_mistral': 920, 'n_tokens_neox': 910, 'n_words': 229}