Java Code Examples for com.typesafe.config.ConfigFactory#parseFile()
The following examples show how to use
com.typesafe.config.ConfigFactory#parseFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compiler.java From kite with Apache License 2.0 | 8 votes |
/** Loads the given config file from the local file system */ public Config parse(File file, Config... overrides) throws IOException { if (file == null || file.getPath().trim().length() == 0) { throw new MorphlineCompilationException("Missing morphlineFile parameter", null); } if (!file.exists()) { throw new FileNotFoundException("File not found: " + file); } if (!file.canRead()) { throw new IOException("Insufficient permissions to read file: " + file); } Config config = ConfigFactory.parseFile(file); for (Config override : overrides) { config = override.withFallback(config); } synchronized (LOCK) { ConfigFactory.invalidateCaches(); config = ConfigFactory.load(config); config.checkValid(ConfigFactory.defaultReference()); // eagerly validate aspects of tree config } return config; }
Example 2
Source File: ActorSystemManager.java From flux with Apache License 2.0 | 6 votes |
/** * Reads the configurations and joins/creates the akka cluster */ @Override public void initialize() { if(withMetrics) { Kamon.start(); } Config config; // check if actor system config file has been passed as part of system parameters String fluxActorsystemConfigurationFile = System.getProperty("flux.actorsystemConfigurationFile"); if(fluxActorsystemConfigurationFile != null) { config = ConfigFactory.parseFile(new File(fluxActorsystemConfigurationFile)); } else { config = ConfigFactory.load(configName); } system = ActorSystem.create(actorSystemName, config); // register the Dead Letter Actor final ActorRef deadLetterActor = system.actorOf(Props.create(DeadLetterActor.class)); system.eventStream().subscribe(deadLetterActor, DeadLetter.class); this.isInitialised = true; registerShutdownHook(); }
Example 3
Source File: UHC.java From UHC with MIT License | 6 votes |
protected Config setupMessagesConfig() throws IOException { // copy reference across saveResource("messages.reference.conf", true); // parse fallback config final File reference = new File(getDataFolder(), "messages.reference.conf"); final Config fallback = ConfigFactory.parseFile(reference); // parse user provided config final File regular = new File(getDataFolder(), "messages.conf"); final Config user; if (regular.exists()) { user = ConfigFactory.parseFile(regular); } else { user = ConfigFactory.empty(); } return user.withFallback(fallback).resolve(ConfigResolveOptions.noSystem()); }
Example 4
Source File: RandomParamsUtils.java From ytk-learn with MIT License | 6 votes |
public static void main(String []args) { Config config = ConfigFactory.parseFile(new File("config/model/fm.conf")); RandomParams randomParams = new RandomParams(config, ""); RandomParamsUtils randomParamsUtils = new RandomParamsUtils(randomParams); System.out.println("normal sample:"); for (int i = 0; i < 50; i++) { System.out.println(randomParamsUtils.next()); } System.out.println("uniform sample:"); for (int i = 0; i < 50000; i++) { double r = randomParamsUtils.next(); if (r < -0.01 || r > 0.01) { System.out.println("error"); break; } } }
Example 5
Source File: ConfigUtils.java From envelope with Apache License 2.0 | 6 votes |
public static Config configFromPath(String path) { File configFile = new File(path); Config config; try { config = ConfigFactory.parseFile(configFile); } catch (ConfigException.Parse e) { // The tell-tale sign is the magic bytes "PK" that is at the start of all jar files if (e.getMessage().contains("Key '\"PK")) { throw new RuntimeException(JAR_FILE_EXCEPTION_MESSAGE); } else { throw e; } } return config; }
Example 6
Source File: MetricSystemTest.java From eagle with Apache License 2.0 | 6 votes |
@Test public void testMerticSystemWithKafkaSink() throws IOException { JVMMetricSource jvmMetricSource = mockMetricRegistry(); //setup kafka KafkaEmbedded kafkaEmbedded = new KafkaEmbedded(); makeSureTopic(kafkaEmbedded.getZkConnectionString()); //setup metric system File file = genKafkaSinkConfig(kafkaEmbedded.getBrokerConnectionString()); Config config = ConfigFactory.parseFile(file); MetricSystem system = MetricSystem.load(config); system.register(jvmMetricSource); system.start(); system.report(); SimpleConsumer consumer = assertMsgFromKafka(kafkaEmbedded); system.stop(); consumer.close(); kafkaEmbedded.shutdown(); }
Example 7
Source File: MetricSystemTest.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testSlf4jSink() throws IOException { PrintStream console = System.out; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); System.setOut(new PrintStream(bytes)); Slf4jSink sink = new Slf4jSink(); MetricRegistry registry = new MetricRegistry(); JvmAttributeGaugeSet jvm = Mockito.mock(JvmAttributeGaugeSet.class); Map<String, Metric> metrics = new HashMap<>(); metrics.put("name", (Gauge) () -> "testname"); metrics.put("uptime", (Gauge) () -> "testuptime"); metrics.put("vendor", (Gauge) () -> "testvendor"); Mockito.when(jvm.getMetrics()).thenReturn(metrics); registry.registerAll(jvm); File file = genSlf4jSinkConfig(); Config config = ConfigFactory.parseFile(file); sink.prepare(config, registry); sink.report(); sink.stop(); String result = bytes.toString(); String finalResult = ""; Scanner scanner = new Scanner(result); while (scanner.hasNext()) { finalResult += scanner.nextLine().substring(DATA_BEGIN_INDEX) + END_LINE; } Assert.assertEquals("type=GAUGE, name=name, value=testname" + END_LINE + "" + "type=GAUGE, name=uptime, value=testuptime" + END_LINE + "" + "type=GAUGE, name=vendor, value=testvendor" + END_LINE + "", finalResult); System.setOut(console); }
Example 8
Source File: TerminalClient.java From philadelphia with Apache License 2.0 | 5 votes |
private static Config config(String filename) throws FileNotFoundException { File file = new File(filename); if (!file.exists() || !file.isFile()) throw new FileNotFoundException(filename + ": No such file"); return ConfigFactory.parseFile(file); }
Example 9
Source File: Configuration.java From BungeeChat2 with GNU General Public License v3.0 | 5 votes |
protected void loadConfig() { final Config defaultConfig = ConfigFactory.parseReader( new InputStreamReader( BungeeChat.getInstance().getResourceAsStream(CONFIG_FILE_NAME), StandardCharsets.UTF_8), PARSE_OPTIONS); final Config strippedDefautConfig = defaultConfig.withoutPath("ServerAlias"); if (CONFIG_FILE.exists()) { try { Config fileConfig = ConfigFactory.parseFile(CONFIG_FILE, PARSE_OPTIONS); config = fileConfig.withFallback(strippedDefautConfig); } catch (ConfigException e) { LoggerHelper.error("Error while reading config:\n" + e.getLocalizedMessage()); config = defaultConfig; } } else { config = defaultConfig; } config = config.resolve(); convertOldConfig(); // Reapply default config. By default this does nothing but it can fix the missing config // settings in some cases config = config.withFallback(strippedDefautConfig); copyComments(defaultConfig); saveConfig(); }
Example 10
Source File: MultiHopFlowCompilerTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * A helper method to return a {@link TopologySpec} map, given a {@link org.apache.gobblin.runtime.spec_catalog.TopologyCatalog}. * @param topologyCatalogUri pointing to the location of the {@link org.apache.gobblin.runtime.spec_catalog.TopologyCatalog} * @return a {@link TopologySpec} map. */ public static Map<URI, TopologySpec> buildTopologySpecMap(URI topologyCatalogUri) throws IOException, URISyntaxException, ReflectiveOperationException { FileSystem fs = FileSystem.get(topologyCatalogUri, new Configuration()); PathFilter extensionFilter = file -> { for (String extension : Lists.newArrayList(".properties")) { if (file.getName().endsWith(extension)) { return true; } } return false; }; Map<URI, TopologySpec> topologySpecMap = new HashMap<>(); for (FileStatus fileStatus : fs.listStatus(new Path(topologyCatalogUri.getPath()), extensionFilter)) { URI topologySpecUri = new URI(Files.getNameWithoutExtension(fileStatus.getPath().getName())); Config topologyConfig = ConfigFactory.parseFile(new File(PathUtils.getPathWithoutSchemeAndAuthority(fileStatus.getPath()).toString())); Class specExecutorClass = Class.forName(topologyConfig.getString(ServiceConfigKeys.SPEC_EXECUTOR_KEY)); SpecExecutor specExecutor = (SpecExecutor) GobblinConstructorUtils.invokeLongestConstructor(specExecutorClass, topologyConfig); TopologySpec.Builder topologySpecBuilder = TopologySpec .builder(topologySpecUri) .withConfig(topologyConfig) .withDescription("") .withVersion("1") .withSpecExecutor(specExecutor); TopologySpec topologySpec = topologySpecBuilder.build(); topologySpecMap.put(topologySpecUri, topologySpec); } return topologySpecMap; }
Example 11
Source File: Example.java From coinbase-fix-example with Apache License 2.0 | 5 votes |
private static Config config(String filename) throws FileNotFoundException { var file = new File(filename); if (!file.exists() || !file.isFile()) throw new FileNotFoundException(filename + ": No such file"); return ConfigFactory.parseFile(file); }
Example 12
Source File: OnlinePredictor.java From ytk-learn with MIT License | 5 votes |
public OnlinePredictor(String configPath) throws Exception { config = ConfigFactory.parseFile(new File(configPath)); LOG.info("load config from file, config_path:" + configPath + ", existed:" + new File(configPath).exists()); String uri = config.getString("fs_scheme"); fs = FileSystemFactory.createFileSystem(new URI(uri)); }
Example 13
Source File: TrainWorker.java From ytk-learn with MIT License | 5 votes |
public String getTrainDataPath() { String configRealPath = (new File(configFile).exists()) ? configFile : configPath; File realFile = new File(configRealPath); CheckUtils.check(realFile.exists(), "config file(%s) doesn't exist!", configRealPath); Config config = ConfigFactory.parseFile(realFile); config = updateConfigWithCustom(config); return config.getString("data.train.data_path"); }
Example 14
Source File: SystemCommander.java From winthing with Apache License 2.0 | 5 votes |
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT") public void parseConfig() { String path = System.getProperty("user.dir") + File.separator + ConfigFile; File fp = new File(path); if (!fp.exists()) { logger.warn("No whitelist found. Every command is allowed to execute on this device!"); return; } try { StringJoiner joiner = new StringJoiner(", "); ConfigParseOptions options = ConfigParseOptions.defaults(); options.setSyntax(ConfigSyntax.CONF); Config cfg = ConfigFactory.parseFile(fp, options); Set<String> map = cfg.root().keySet(); for (String key : map) { whitelist.put(key, cfg.getString(key)); joiner.add(key); } logger.info("Found whitelist of allowed commands to execute, using it..."); logger.info("Allowed commands: [" + joiner.toString() + "]"); isEnabled = true; } catch (Exception e) { logger.error("Unable to process whitelist file", e); } }
Example 15
Source File: PrettyPrinter.java From kite with Apache License 2.0 | 5 votes |
public static void main(String[] args) { if (args.length ==0) { System.err.println("Usage: java -cp ... " + PrettyPrinter.class.getName() + " <morphlineConfigFile>"); return; } Config config = ConfigFactory.parseFile(new File(args[0])); String str = config.root().render( ConfigRenderOptions.concise().setFormatted(true).setJson(false).setComments(true)); System.out.println(str); }
Example 16
Source File: LossParams.java From ytk-learn with MIT License | 4 votes |
public static void main(String []args) { Config config = ConfigFactory.parseFile(new File("config/model/linear.conf")); LossParams params = new LossParams(config, ""); System.out.println(params.toString()); }
Example 17
Source File: DataParams.java From ytk-learn with MIT License | 4 votes |
public static void main(String []args) { Config config = ConfigFactory.parseFile(new File("config/model/linear.conf")); DataParams params = new DataParams(config, ""); System.out.println(params.toString()); }
Example 18
Source File: ModelParams.java From ytk-learn with MIT License | 4 votes |
public static void main(String []args) { Config config = ConfigFactory.parseFile(new File("config/model/linear.conf")); ModelParams params = new ModelParams(config, ""); System.out.println(params.toString()); }
Example 19
Source File: ConfigFileEnvironment.java From pdfcompare with Apache License 2.0 | 4 votes |
public ConfigFileEnvironment(Path path) { Objects.requireNonNull(path, "path is null"); this.config = ConfigFactory.parseFile(path.toFile(), CONFIG_PARSE_OPTIONS); }
Example 20
Source File: AkkaSourceTest.java From bahir-flink with Apache License 2.0 | 4 votes |
private Config getFeederActorConfig() { String configFile = getClass().getClassLoader() .getResource("feeder_actor.conf").getFile(); Config config = ConfigFactory.parseFile(new File(configFile)); return config; }