Java Code Examples for com.typesafe.config.ConfigFactory#parseReader()
The following examples show how to use
com.typesafe.config.ConfigFactory#parseReader() .
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: PluginManager.java From andesite-node with MIT License | 6 votes |
public Config applyPluginDefaults(@Nonnull Config config) { for(var l : loaders) { if(l.hasFile("reference.conf")) { log.info("Loading reference.conf from {}", l); try(var reader = new BufferedReader(new InputStreamReader( Objects.requireNonNull(l.openFile("reference.conf"))) )) { var reference = ConfigFactory.parseReader(reader); log.debug("Loaded reference.conf from {}: {}", l, reference.root().render()); config = config.withFallback(reference.resolveWith(config)); } catch(IOException e) { throw new IllegalStateException("reference.conf exists but cannot be read", e); } } } return config; }
Example 2
Source File: Configuration.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * constructor. */ public static Config getByPath(final String configurationPath) { if (isBlank(configurationPath)) { throw new IllegalArgumentException("Configuration path is required!"); } if (config == null) { File configFile = new File(System.getProperty("user.dir") + '/' + configurationPath); if (configFile.exists()) { try { config = ConfigFactory.parseReader(new InputStreamReader(new FileInputStream(configurationPath))); logger.info("use user defined config file in current dir"); } catch (FileNotFoundException e) { logger.error("load user defined config file exception: " + e.getMessage()); } } else { config = ConfigFactory.load(configurationPath); logger.info("user defined config file doesn't exists, use default config file in jar"); } } return config; }
Example 3
Source File: ZipFileConfigStore.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Retrieves the {@link Config} for the given {@link ConfigKeyPath}. Similar to * {@link SimpleHadoopFilesystemConfigStore#getOwnConfig} */ @Override public Config getOwnConfig(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException { Preconditions.checkNotNull(configKey, "configKey cannot be null!"); Preconditions.checkArgument(version.equals(getCurrentVersion())); Path datasetDir = getDatasetDirForKey(configKey); Path mainConfFile = this.fs.getPath(datasetDir.toString(), SimpleHadoopFilesystemConfigStore.MAIN_CONF_FILE_NAME); try { if (!Files.exists(mainConfFile)) { return ConfigFactory.empty(); } if (!Files.isDirectory(mainConfFile)) { try (InputStream mainConfInputStream = Files.newInputStream(mainConfFile)) { return ConfigFactory.parseReader(new InputStreamReader(mainConfInputStream, Charsets.UTF_8)); } } return ConfigFactory.empty(); } catch (IOException e) { throw new RuntimeException(String.format("Error while getting config for configKey: \"%s\"", configKey), e); } }
Example 4
Source File: SimpleHadoopFilesystemConfigStore.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Retrieves the {@link Config} for the given {@link ConfigKeyPath} by reading the {@link #MAIN_CONF_FILE_NAME} * associated with the dataset specified by the given {@link ConfigKeyPath}. If the {@link Path} described by the * {@link ConfigKeyPath} does not exist then an empty {@link Config} is returned. * * @param configKey the config key path whose properties are needed. * @param version the configuration version in the configuration store. * * @return a {@link Config} for the given configKey. * * @throws VersionDoesNotExistException if the version specified cannot be found in the {@link ConfigStore}. */ @Override public Config getOwnConfig(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException { Preconditions.checkNotNull(configKey, "configKey cannot be null!"); Preconditions.checkArgument(!Strings.isNullOrEmpty(version), "version cannot be null or empty!"); Path datasetDir = getDatasetDirForKey(configKey, version); Path mainConfFile = new Path(datasetDir, MAIN_CONF_FILE_NAME); try { if (!this.fs.exists(mainConfFile)) { return ConfigFactory.empty(); } FileStatus configFileStatus = this.fs.getFileStatus(mainConfFile); if (!configFileStatus.isDirectory()) { try (InputStream mainConfInputStream = this.fs.open(configFileStatus.getPath())) { return ConfigFactory.parseReader(new InputStreamReader(mainConfInputStream, Charsets.UTF_8)); } } return ConfigFactory.empty(); } catch (IOException e) { throw new RuntimeException(String.format("Error while getting config for configKey: \"%s\"", configKey), e); } }
Example 5
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 6
Source File: ConfigurationTest.java From BungeeChat2 with GNU General Public License v3.0 | 5 votes |
@Test public void versionMatchTest() { Config defaultConfig = ConfigFactory.parseReader( new InputStreamReader( BungeeChat.getInstance().getResourceAsStream(Configuration.CONFIG_FILE_NAME), StandardCharsets.UTF_8), Configuration.PARSE_OPTIONS); assertEquals(defaultConfig.getDouble("Version"), BungeeChatApi.CONFIG_VERSION, 0.0); }
Example 7
Source File: OnlinePredictor.java From ytk-learn with MIT License | 5 votes |
public OnlinePredictor(Reader configReader) throws Exception { config = ConfigFactory.parseReader(configReader); LOG.info("load config from reader!"); String uri = config.getString("fs_scheme"); fs = FileSystemFactory.createFileSystem(new URI(uri)); }
Example 8
Source File: ConfigUtils.java From envelope with Apache License 2.0 | 5 votes |
public static Config configFromResource(String resource) { try (Reader reader = new InputStreamReader(ConfigUtils.class.getResourceAsStream(resource))) { return ConfigFactory.parseReader(reader); } catch (IOException e) { throw new RuntimeException(e); } }
Example 9
Source File: SimpleHDFSStoreMetadata.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Get all metadata from the {@link #CONFIG_STORE_METADATA_FILENAME} file at {@link #storeMetadataFilePath} * */ Config readMetadata() throws IOException { if (!isStoreMetadataFilePresent()) { throw new IOException("Store metadata file does not exist at " + this.storeMetadataFilePath); } try (InputStream storeMetadataInputStream = this.fs.open(this.storeMetadataFilePath)) { return ConfigFactory.parseReader(new InputStreamReader(storeMetadataInputStream, Charsets.UTF_8)); } }
Example 10
Source File: MultiHopFlowCompilerTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private FlowSpec createFlowSpec(String flowConfigResource, String source, String destination, boolean applyRetention, boolean applyRetentionOnInput) throws IOException, URISyntaxException { //Create a flow spec Properties flowProperties = new Properties(); flowProperties.put(ConfigurationKeys.JOB_SCHEDULE_KEY, "* * * * *"); flowProperties.put(ConfigurationKeys.FLOW_GROUP_KEY, "testFlowGroup"); flowProperties.put(ConfigurationKeys.FLOW_NAME_KEY, "testFlowName"); flowProperties.put(ServiceConfigKeys.FLOW_SOURCE_IDENTIFIER_KEY, source); flowProperties.put(ServiceConfigKeys.FLOW_DESTINATION_IDENTIFIER_KEY, destination); flowProperties.put(ConfigurationKeys.FLOW_APPLY_RETENTION, Boolean.toString(applyRetention)); flowProperties.put(ConfigurationKeys.FLOW_APPLY_INPUT_RETENTION, Boolean.toString(applyRetentionOnInput)); Config flowConfig = ConfigUtils.propertiesToConfig(flowProperties); //Get the input/output dataset config from a file URI flowConfigUri = MultiHopFlowCompilerTest.class.getClassLoader().getResource(flowConfigResource).toURI(); Path flowConfigPath = new Path(flowConfigUri); FileSystem fs1 = FileSystem.get(flowConfigUri, new Configuration()); try (InputStream is = fs1.open(flowConfigPath)) { Config datasetConfig = ConfigFactory.parseReader(new InputStreamReader(is, Charset.defaultCharset())); flowConfig = flowConfig.withFallback(datasetConfig).resolve(); } FlowSpec.Builder flowSpecBuilder = null; flowSpecBuilder = FlowSpec.builder(new Path("/tmp/flowSpecCatalog").toUri()) .withConfig(flowConfig) .withDescription("dummy description") .withVersion(FlowSpec.Builder.DEFAULT_VERSION); FlowSpec spec = flowSpecBuilder.build(); return spec; }
Example 11
Source File: StateStoreMigrationCli.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Override public void run(String[] args) throws Exception { CliObjectFactory<Command> factory = new ConstructorAndPublicMethodsCliObjectFactory<>(Command.class); Command command = factory.buildObject(args, 1, true, args[0]); FileSystem fs = FileSystem.get(new Configuration()); FSDataInputStream inputStream = fs.open(command.path); Config config = ConfigFactory.parseReader(new InputStreamReader(inputStream, Charset.defaultCharset())); Preconditions.checkNotNull(config.getObject(SOURCE_KEY)); Preconditions.checkNotNull(config.getObject(DESTINATION_KEY)); DatasetStateStore dstDatasetStateStore = DatasetStateStore.buildDatasetStateStore(config.getConfig(DESTINATION_KEY)); DatasetStateStore srcDatasetStateStore = DatasetStateStore.buildDatasetStateStore(config.getConfig(SOURCE_KEY)); Map<String, JobState.DatasetState> map; // if migrating state for all jobs then list the store names (job names) and copy the current jst files if (ConfigUtils.getBoolean(config, MIGRATE_ALL_JOBS, Boolean.valueOf(DEFAULT_MIGRATE_ALL_JOBS))) { List<String> jobNames = srcDatasetStateStore.getStoreNames(Predicates.alwaysTrue()); for (String jobName : jobNames) { migrateStateForJob(srcDatasetStateStore, dstDatasetStateStore, jobName, command.deleteSourceStateStore); } } else { Preconditions.checkNotNull(config.getString(JOB_NAME_KEY)); migrateStateForJob(srcDatasetStateStore, dstDatasetStateStore, config.getString(JOB_NAME_KEY), command.deleteSourceStateStore); } }
Example 12
Source File: IntegrationBasicSuite.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private void copyJobConfFromResource() throws IOException { Map<String, Config> jobConfigs; try (InputStream resourceStream = this.jobConfResourceUrl.openStream()) { Reader reader = new InputStreamReader(resourceStream); Config rawJobConfig = ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF)); jobConfigs = overrideJobConfigs(rawJobConfig); jobConfigs.forEach((jobName, jobConfig)-> { try { writeJobConf(jobName, jobConfig); } catch (IOException e) { log.error("Job " + jobName + " config cannot be written."); } }); } }
Example 13
Source File: IntegrationJobRestartViaSpecSuite.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private Config getJobConfig() throws IOException { try (InputStream resourceStream = Resources.getResource(JOB_CONF_NAME).openStream()) { Reader reader = new InputStreamReader(resourceStream); Config rawJobConfig = ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF)); rawJobConfig = rawJobConfig.withFallback(getClusterConfig()); Config newConfig = ClusterIntegrationTestUtils.buildSleepingJob(JOB_ID, TASK_STATE_FILE, 100L); newConfig = newConfig.withValue(SleepingTask.TASK_STATE_FILE_KEY, ConfigValueFactory.fromAnyRef(TASK_STATE_FILE)); newConfig = newConfig.withFallback(rawJobConfig); return newConfig; } }
Example 14
Source File: ConfigFileEnvironment.java From pdfcompare with Apache License 2.0 | 4 votes |
public ConfigFileEnvironment(Reader reader) { Objects.requireNonNull(reader, "reader is null"); this.config = ConfigFactory.parseReader(reader, CONFIG_PARSE_OPTIONS); }
Example 15
Source File: FSFlowTemplateCatalog.java From incubator-gobblin with Apache License 2.0 | 4 votes |
private Config loadHoconFileAtPath(Path filePath) throws IOException { try (InputStream is = fs.open(filePath)) { return ConfigFactory.parseReader(new InputStreamReader(is, Charsets.UTF_8)); } }
Example 16
Source File: HOCONInputStreamJobTemplate.java From incubator-gobblin with Apache License 2.0 | 4 votes |
/** * Load a template from an {@link InputStream}. Caller is responsible for closing {@link InputStream}. */ public HOCONInputStreamJobTemplate(InputStream inputStream, URI uri, JobCatalogWithTemplates catalog) throws SpecNotFoundException, TemplateException { this(ConfigFactory.parseReader(new InputStreamReader(inputStream, Charsets.UTF_8)), uri, catalog); }