@Override public void scrubRegistrationProperties() { if (!exist()) { return; } try { PropertiesConfiguration config = new PropertiesConfiguration(); config.setIOFactory(new FilteringOutputWriterFactory()); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); layout.setLineSeparator("\n"); layout.load(config, reader()); try (FileWriter out = new FileWriter(this.configFile)) { layout.save(config, out); } loadProperties(); } catch (ConfigurationException | IOException e) { LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e); } }
/** * Creates a standard layout object. This configuration is initialized with * such a standard layout. * * @return the newly created layout object */ private PropertiesConfigurationLayout createLayout() { return new PropertiesConfigurationLayout(); }
/** * Creates a copy of this object. * * @return the copy */ @Override public Object clone() { final PropertiesConfiguration copy = (PropertiesConfiguration) super.clone(); if (layout != null) { copy.setLayout(new PropertiesConfigurationLayout(layout)); } return copy; }
private PropertiesConfiguration loadPropertiesFile(File file, PropertiesConfiguration config) { PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStreamReader is = new InputStreamReader(new FileInputStream(file))) { layout.load(config, is); } catch (ConfigurationException | FileNotFoundException e) { LOGGER.log(Level.WARNING, "Failed to load " + file.getPath(), e); } catch (IOException e) { e.printStackTrace(); } config.setLayout(layout); return config; } }
public String getValue(String property) { String propertyValue = EMPTY; PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); propertyValue = config.getString(property); } catch (Exception e) { LOGGER.error(e.getMessage()); } return propertyValue; }
public Map<String, String> getKeysAndValues() { Map<String, String> kvp = newLinkedHashMap(); PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); config.getKeys().forEachRemaining(item -> kvp.put(item, config.getString(item))); } catch (Exception e) { LOGGER.error(e.getMessage()); } return kvp; }
public void setValue(String property, String propertyValue) { PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); try (InputStream input = new FileInputStream(props)) { layout.load(config, new InputStreamReader(input, UTF_8)); config.setProperty(property, propertyValue); layout.save(config, new FileWriter(props, false)); } catch (Exception e) { LOGGER.error(e.getMessage()); } } }
public BinanceAutoBlacklist() { cache = new HashMap<>(); scheduler = Executors.newSingleThreadScheduledExecutor(); settings = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); settings.setLayout(layout); if (!settingsFile.exists()) { settings.setProperty("enabled", enabled = true); settings.setProperty("interval", interval = 30); settings.setProperty("market", market = "BTC"); settings.setProperty("days", days = 14); settings.setProperty("clear", clear = true); try (FileWriter fw = new FileWriter(settingsFile, false)) { settings.write(fw); } catch (ConfigurationException | IOException e) { LOGGER.log(Level.WARNING, "Failed to save " + settingsFile.getName(), e); } LOGGER.info("Created " + settingsFile.getPath()); currentInterval = interval; start(); } else { updateSettings(); } }