public Swagger2MarkupConfigBuilder() { this(new PropertiesConfiguration()); }
@Override public synchronized String currentConfig() { PropertiesConfiguration saver = new PropertiesConfiguration(); StringWriter writer = new StringWriter(); saver.copy(config); try { saver.write(writer); } catch (Exception e) { throw new MetricsConfigException("Error stringify config", e); } return writer.toString(); }
static String toString(Configuration c) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { PrintWriter pw = new PrintWriter(buffer, false); PropertiesConfiguration tmp = new PropertiesConfiguration(); tmp.copy(c); tmp.write(pw); return buffer.toString("UTF-8"); } catch (Exception e) { throw new MetricsConfigException(e); } } }
for (String fname : fileNames) { try { PropertiesConfiguration pcf = new PropertiesConfiguration(); FileHandler fh = new FileHandler(pcf); fh.setFileName(fname); Joiner.on(",").join(fileNames)); return new MetricsConfig(new PropertiesConfiguration(), prefix);
@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); } }
/** * Sets system properties from a file specified using its base path and * file name. The file can either be a properties file or an XML properties * file. It is loaded, and all properties it contains are added to system * properties. * * @param basePath The base path to look for the property file. * @param fileName The name of the property file. * @throws ConfigurationException if an error occurs. * @since 1.6 */ public static void setSystemProperties(final String basePath, final String fileName) throws ConfigurationException { final FileBasedConfiguration config = fileName.endsWith(".xml") ? new XMLPropertiesConfiguration() : new PropertiesConfiguration(); final FileHandler handler = new FileHandler(config); handler.setBasePath(basePath); handler.setFileName(fileName); handler.load(); setSystemProperties(config); }
public Swagger2MarkupConfigBuilder() { this(new PropertiesConfiguration()); }
public Swagger2MarkupConfigBuilder() { this(new PropertiesConfiguration()); }
/** Create new settings object and initialize it with defaults */ public IncrementalDataPlaneSettings() { _config = new PropertiesConfiguration(); initDefaults(); }
private PropertiesConfiguration loadPropertiesFile(File file) { return loadPropertiesFile(file, new PropertiesConfiguration()); }
public static void loadResource(String path) { try { PropertiesConfiguration props = new PropertiesConfiguration(); props.read(new FileReader(path)); config.append(props); } catch (IOException | ConfigurationException ex) { throw new RuntimeException("Failed to load config resource: " + path, ex); } log.debug("Configuration file loaded: {}", path); }
public static void loadResource(InputStream stream, String resourceName) { try { PropertiesConfiguration props = new PropertiesConfiguration(); props.read(new InputStreamReader(stream)); config.append(props); } catch (IOException | ConfigurationException ex) { throw new RuntimeException("Failed to load config resource: " + resourceName, ex); } log.debug("Configuration stream loaded: {}", resourceName); }
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 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 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()); } } }
/** * @param resourcePath Path of overlapping properties files * @param classLoader Class loader where the resources are loaded * @return Configuration result * @throws IOException allows IO exceptions. */ public static Configuration loadFromOverlappingResources(String resourcePath, ClassLoader classLoader) throws IOException { Validate.notNull(resourcePath, "Resource path can't be NULL"); Validate.notNull(classLoader, "ClassLoader can't be NULL"); PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiterHandler(new DefaultListDelimiterHandler(',')); Enumeration<URL> resources = classLoader.getResources(resourcePath); while (resources.hasMoreElements()) { InputStream resource = resources.nextElement().openStream(); Reader reader = new InputStreamReader(resource); try { props.read(reader); } catch (ConfigurationException e) { throw new IOException(e); } finally { reader.close(); } } return props; }
@Override public Configuration getConfiguration(RepositoryFileReference ref) { Path path = this.ref2AbsolutePath(ref); PropertiesConfiguration configuration = new PropertiesConfiguration(); if (Files.exists(path)) { try (Reader r = Files.newBufferedReader(path, Charset.defaultCharset())) { configuration.read(r); } catch (ConfigurationException | IOException e) { FilebasedRepository.LOGGER.error("Could not read config file", e); throw new IllegalStateException("Could not read config file", e); } } configuration.addEventListener(ConfigurationEvent.ANY, new AutoSaveListener(path, configuration)); // We do NOT implement reloading as the configuration is only accessed // in JAX-RS resources, which are created on a per-request basis return configuration; }
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(); } }
protected void loadConfiguration(ServletContext servletContext, FileObject applicationRoot) throws FileSystemException, ConfigurationException { FileObject configurationFile = applicationRoot.getChild("portofino.properties"); WritableCompositeConfiguration compositeConfiguration = new WritableCompositeConfiguration(); if(configurationFile != null) { Configurations configurations = new Configurations(); PropertiesConfiguration configuration = configurations.properties(configurationFile.getURL()); FileObject localConfigurationFile = applicationRoot.getChild("portofino-local.properties"); if (localConfigurationFile != null && localConfigurationFile.exists() && localConfigurationFile.getType() == FileType.FILE) { logger.info("Local configuration found: {}", localConfigurationFile); PropertiesConfiguration localConfiguration = configurations.properties(localConfigurationFile.getURL()); compositeConfiguration.addConfiguration(localConfiguration); } compositeConfiguration.addConfiguration(configuration); this.configuration = compositeConfiguration; } else { this.configuration = new PropertiesConfiguration(); logger.warn("portofino.properties file not found in " + applicationRoot); } servletContext.setAttribute("portofino.configuration", this.configuration); }
/** * Creates application composite configuration. * * @return Application composite configuration. */ private CompositeConfiguration createApplicationConfiguration() { CompositeConfiguration cc = new CompositeConfiguration(); SystemConfiguration systemConfiguration = new SystemConfiguration(); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setThrowExceptionOnMissing(true); propertiesConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(';')); propertiesConfiguration.setIncludesAllowed(false); FileLocator locator = FileLocatorUtils.fileLocator() .fileName("testlinkjavaapi.propertiesxml") .create(); propertiesConfiguration.initFileLocator(locator); cc.addConfiguration(systemConfiguration); cc.addConfiguration(propertiesConfiguration); return cc; }