Java Code Examples for org.ini4j.Ini#get()
The following examples show how to use
org.ini4j.Ini#get() .
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: AutoHelper.java From jolie with GNU Lesser General Public License v2.1 | 6 votes |
public static String getLocationFromIni( String iniLocation ) throws IOException { // Format: "/Section/Key:URL_to_ini" String[] ss = iniLocation.split( ":", 2 ); assertIOException( ss.length < 2, "invalid ini location; the format is /Section/Key:URL_to_ini" ); String[] iniPath = ss[ 0 ].split( "/", 3 ); assertIOException( iniPath.length < 3, "path to ini content is not well-formed; the format is /Section/Key" ); URL iniURL = new URL( ss[ 1 ] ); try( Reader reader = new InputStreamReader( iniURL.openStream() ) ) { Ini ini = new Ini( reader ); Ini.Section section = ini.get( iniPath[ 1 ] ); assertIOException( section == null, "could not find section " + iniPath[ 1 ] + " in ini" ); String retLocation = section.get( iniPath[ 2 ] ); assertIOException( retLocation == null, "could not find key " + iniPath[ 2 ] + " in section " + iniPath[ 1 ] + " in ini" ); return retLocation; } }
Example 2
Source File: FromHereCredentialsIniStream.java From here-aaa-java-sdk with Apache License 2.0 | 6 votes |
static Properties getPropertiesFromIni(InputStream inputStream, String sectionName) throws IOException { Ini ini = new Ini(); try (Reader reader = new InputStreamReader(inputStream, OAuthConstants.UTF_8_CHARSET)) { ini.load(reader); Ini.Section section = ini.get(sectionName); Properties properties = new Properties(); properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY, section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY)); properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY, section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY)); properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY, section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY)); // scope is optional String scope = section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY); if (null != scope) properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY, scope); return properties; } }
Example 3
Source File: SdkIniFileReader.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Read sdk.ini file (or file tree with includes) from the given location. * @param xdsHomePath - folder to search sdk.ini file */ public SdkIniFileReader(String xdsHomePath) { aSdk = new ArrayList<Sdk>(); sbErrLog = new StringBuilder(); try { Ini ini = loadFile(xdsHomePath, MAIN_INI_FILE_NAME, true); if (ini != null) { Section global = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME); List<String> imports = global.getAll(IMPORT_PROPERTY); if ((imports == null) || imports.isEmpty()) { processIniFile(xdsHomePath, MAIN_INI_FILE_NAME); } else { for (String import_file_name: imports) { processIniFile(xdsHomePath, import_file_name); } } } } catch (Exception e) { LogHelper.logError(e); aSdk.clear(); setError(e.getMessage()); } }
Example 4
Source File: SvnConfigFiles.java From netbeans with Apache License 2.0 | 6 votes |
/** * Merges only sections/keys/values into target which are not already present in source * * @param source the source ini file * @param target the target ini file in which the values from the source file are going to be merged */ private void merge(Ini source, Ini target) { for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext();) { String sectionName = itSections.next(); Ini.Section sourceSection = source.get( sectionName ); Ini.Section targetSection = target.get( sectionName ); if(targetSection == null) { targetSection = target.add(sectionName); } for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext();) { String key = itVariables.next(); if(!targetSection.containsKey(key)) { targetSection.put(key, sourceSection.get(key)); } } } }
Example 5
Source File: SvnConfigFilesTest.java From netbeans with Apache License 2.0 | 6 votes |
private void isSubsetOf(String sourceIniPath, String expectedIniPath) throws IOException { Ini goldenIni = new Ini(new FileInputStream(expectedIniPath)); Ini sourceIni = new Ini(new FileInputStream(sourceIniPath)); for(String key : goldenIni.keySet()) { if(!sourceIni.containsKey(key) && goldenIni.get(key).size() > 0) { fail("missing section " + key + " in file " + sourceIniPath); } Section goldenSection = goldenIni.get(key); Section sourceSection = sourceIni.get(key); for(String name : goldenSection.childrenNames()) { if(!sourceSection.containsKey(name)) { fail("missing name " + name + " in file " + sourceIniPath + " section [" + name + "]"); } assertEquals(goldenSection.get(name), sourceSection.get(name)); } } }
Example 6
Source File: HgConfigFiles.java From netbeans with Apache License 2.0 | 6 votes |
/** * Merges only sections/keys/values into target which are not already present in source * * @param source the source ini file * @param target the target ini file in which the values from the source file are going to be merged */ private void merge(Ini source, Ini target) { for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext();) { String sectionName = itSections.next(); Ini.Section sourceSection = source.get( sectionName ); Ini.Section targetSection = target.get( sectionName ); if(targetSection == null) { targetSection = target.add(sectionName); } for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext();) { String key = itVariables.next(); if(!targetSection.containsKey(key)) { targetSection.put(key, sourceSection.get(key)); } } } }
Example 7
Source File: IniTest.java From buck with Apache License 2.0 | 5 votes |
@Test public void testSecondaryLoadOverridesOriginalDefs() throws IOException { Ini ini = Inis.makeIniParser(false); Reader originalInput = new StringReader( Joiner.on("\n") .join( "[alias]", " buck = //src/com/facebook/buck/cli:cli", "[cache]", " mode = dir")); Reader overrideInput = new StringReader( Joiner.on("\n") .join( "[alias]", " test_util = //test/com/facebook/buck/util:util", "[cache]", " mode =")); ini.load(originalInput); ini.load(overrideInput); Section aliasSection = ini.get("alias"); assertEquals( "Should be the union of the two [alias] sections.", ImmutableMap.of( "buck", "//src/com/facebook/buck/cli:cli", "test_util", "//test/com/facebook/buck/util:util"), aliasSection); Section cacheSection = ini.get("cache"); assertEquals( "Values from overrideInput should supercede those from originalInput, as appropriate.", ImmutableMap.of("mode", ""), cacheSection); }
Example 8
Source File: PersistentTokenDescriptor.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public void preferenciesFromIni(Ini ini) { String s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, styleId); if (s != null) { styleWhenEnabled = Integer.parseInt(s); } else { styleWhenEnabled = getDefaultStyle(); } s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, disabledId); if (s != null) { isDisabled = (Integer.parseInt(s) != 0); } else { isDisabled = false; } s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, colorId); if (s != null) { rgbWhenEnabled = StringConverter.asRGB(s, getDefaultRgb()); } else { rgbWhenEnabled = getDefaultRgb(); } if (isDisabled && iTokens != null) { PersistentTokenDescriptor pt = iTokens.getDefaultColoring(); TextAttributeDescriptor ta = pt.getTextAttribute(); if (ta != null) { setTextAttribute(new TextAttributeDescriptor(ta.getForeground(), null, ta.getStyle())); } } else { setTextAttribute(new TextAttributeDescriptor(rgbWhenEnabled, null, styleWhenEnabled)); } }
Example 9
Source File: Utilities.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
/** * This method read a application descriptor file and return a {@link org.openqa.selenium.By} object (xpath, id, link ...). * * @param applicationKey * Name of application. Each application has its fair description file. * @param code * Name of element on the web Page. * @param args * list of description (xpath, id, link ...) for code. * @return a {@link org.openqa.selenium.By} object (xpath, id, link ...) */ public static By getLocator(String applicationKey, String code, Object... args) { By locator = null; log.debug("getLocator with this application key : {}", applicationKey); log.debug("getLocator with this code : {}", code); log.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey)); final Ini ini = Context.iniFiles.get(applicationKey); final Map<String, String> section = ini.get(code); if (section != null) { final Entry<String, String> entry = section.entrySet().iterator().next(); final String selector = String.format(entry.getValue(), args); if ("css".equals(entry.getKey())) { locator = By.cssSelector(selector); } else if ("link".equals(entry.getKey())) { locator = By.linkText(selector); } else if ("id".equals(entry.getKey())) { locator = By.id(selector); } else if ("name".equals(entry.getKey())) { locator = By.name(selector); } else if ("xpath".equals(entry.getKey())) { locator = By.xpath(selector); } else if ("class".equals(entry.getKey())) { locator = By.className(selector); } else { Assert.fail(entry.getKey() + " NOT implemented!"); } } else { Assert.fail("[" + code + "] NOT implemented in ini file " + Context.iniFiles.get(applicationKey) + "!"); } return locator; }
Example 10
Source File: Utilities.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
/** * @param applicationKey * is key of application * @param code * is key of selector (CAUTION: if you use any % char. {@link String#format(String, Object...)}) * @param args * is list of args ({@link String#format(String, Object...)}) * @return the selector */ public static String getSelectorValue(String applicationKey, String code, Object... args) { String selector = ""; log.debug("getLocator with this application key : {}", applicationKey); log.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey)); final Ini ini = Context.iniFiles.get(applicationKey); final Map<String, String> section = ini.get(code); if (section != null) { final Entry<String, String> entry = section.entrySet().iterator().next(); selector = String.format(entry.getValue(), args); } return selector; }
Example 11
Source File: HgConfigFiles.java From netbeans with Apache License 2.0 | 5 votes |
private Ini.Section getSection(Ini ini, String key, boolean create) { Ini.Section section = ini.get(key); if(section == null && create) { return ini.add(key); } return section; }
Example 12
Source File: SvnConfigFilesTest.java From netbeans with Apache License 2.0 | 5 votes |
private Section getSection(File serversFile) throws FileNotFoundException, IOException { FileInputStream is = new FileInputStream(serversFile); Ini ini = new Ini(); try { ini.load(is); } finally { is.close(); } return ini.get("global"); }
Example 13
Source File: SvnConfigFiles.java From netbeans with Apache License 2.0 | 5 votes |
private Ini.Section getSection(Ini ini, String key, boolean create) { Ini.Section section = ini.get(key); if(section == null) { return ini.add(key); } return section; }
Example 14
Source File: SvnConfigFiles.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void patch(Ini file) { // patch store-auth-creds to "no" Ini.Section auth = (Ini.Section) file.get("auth"); // NOI18N if(auth == null) { auth = file.add("auth"); // NOI18N } auth.put("store-auth-creds", "yes"); // NOI18N auth.put("store-passwords", "no"); // NOI18N auth.put("password-stores", ""); // NOI18N }
Example 15
Source File: IniUtil.java From spring-boot-plus with Apache License 2.0 | 5 votes |
public static Map<String,String> parseIni(String string) { Config config = new Config(); config.setGlobalSection(true); config.setGlobalSectionName(""); Ini ini = new Ini(); ini.setConfig(config); try { ini.load(new StringReader(string)); Profile.Section section = ini.get(""); return section; } catch (IOException e) { e.printStackTrace(); } return null; }
Example 16
Source File: DescriptorParser.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
private static String getUpdateDescrpitorURI(File updatePropertiesFile) throws InvalidFileFormatException, IOException { final Ini ini = new Ini(updatePropertiesFile); return ini.get(GENERAL_INI_SECTION, UPDATE_DIR_PROPERTY_NAME); }
Example 17
Source File: SdkIniFileReader.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
private void processIniFile(String basePath, String fileName) throws Exception { Ini ini = loadFile(basePath, fileName, false); String homePath = ini.getFile().getParentFile().getCanonicalPath(); Sdk sdk = SdkManager.createSdk(); sdk.setPropertyInternal(Property.XDS_HOME, homePath); for (Sdk.Property property: Sdk.Property.values()) { String val = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, property.key); // '?' for the default (global) section if (val != null) { switch (property) { case XDS_NAME: sdk.setPropertyInternal(Property.XDS_NAME, val); break; case XDS_HOME: sdk.setPropertyInternal(Property.XDS_HOME, makePath(homePath, val)); break; case XDS_EXE_EXTENSION: sdk.setPropertyInternal(Property.XDS_EXE_EXTENSION, val); break; case XDS_PRIM_EXTENSIONS: sdk.setPropertyInternal(Property.XDS_PRIM_EXTENSIONS, val); break; default: if ( Sdk.Property.XDS_XSHELL_FORMAT.equals(property) || Sdk.Property.XDS_DIRS_TO_CREATE.equals(property) || Sdk.Property.XDS_FOLDER_PRJ_FILE.equals(property) || Sdk.Property.XDS_FOLDER_MAIN_MODULE.equals(property)) { sdk.setPropertyInternal(property, val); } else { sdk.setPropertyInternal(property, makePathNS(homePath, val)); } } } for (Sdk.Tag tag : property.possibleTags) { String tval = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, property.key + "." + tag.tagName); //$NON-NLS-1$ if (tval != null) { sdk.setTag(property, tag, tval); } } } adjustSettings(ini.getFile(), sdk); // Get additional settings from xds.ini etc.: addSettingsFromLocation(sdk); processEnvironmentSection(sdk, ini); processToolSections(sdk, ini); aSdk.add(sdk); }
Example 18
Source File: LocalIdentity.java From ts3j with Apache License 2.0 | 4 votes |
/** * Reads a TS3 identity from a given input stream. * @param inputStream Input stream to read * @return local identity */ public static final LocalIdentity read(InputStream inputStream) throws IOException { Ini ini = new Ini(inputStream); String identityValue = ini.get("Identity", "identity"); if (identityValue == null) throw new IOException(new IllegalArgumentException("missing identity value")); Matcher matcher = identityPattern.matcher(identityValue); if (!matcher.matches()) throw new IOException(new IllegalArgumentException("invalid INI file")); long level = Long.parseUnsignedLong(matcher.group(1)); //var ident = Base64Decode(match.Groups["identity"].Value); byte[] identityData = Base64.getDecoder().decode(matcher.group(2)); if (identityData.length < 20) throw new IOException(new IllegalArgumentException("identity data too short")); //int nullIdx = identityArr.AsSpan(20).IndexOf((byte)0); int nullIndex = -1; for (int i = 20; i < identityData.length; i ++) if (identityData[i] == 0x0) { nullIndex = i-20; break; } //var hash = Hash1It(identityArr, 20, nullIdx < 0 ? identityArr.Length - 20 : nullIdx); byte[] hash = Ts3Crypt.hash128( identityData, 20, nullIndex < 0 ? identityData.length - 20 : nullIndex ); //XorBinary(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b, int len, Span<byte> outBuf) //XorBinary(identityArr, hash, 20, identityArr); Ts3Crypt.xor( identityData, 0, hash, 0, 20, identityData, 0 ); //XorBinary(identityArr, Ts3IdentityObfuscationKey, Math.Min(100, identityArr.Length), identityArr); Ts3Crypt.xor( identityData, 0, identityFileObfuscationKey, 0, Math.min(100, identityData.length), identityData, 0 ); String utf8Decoded = new String(identityData, Charset.forName("UTF8")); LocalIdentity identity = Ts3Crypt.loadIdentityFromAsn(Base64.getDecoder().decode(utf8Decoded)); identity.setKeyOffset(level); identity.setLastCheckedKeyOffset(level); return identity; }
Example 19
Source File: CreateClustersSample.java From director-sdk with Apache License 2.0 | 4 votes |
/** * Create a new environment with data from the configuration file. * * @param client authenticated API client * @param config parsed configuration file * @return the name of the new environment * @throws FileNotFoundException if the key file can't be found * @throws ApiException */ private String createEnvironment(ApiClient client, Ini config) throws FileNotFoundException, ApiException { String clusterName = config.get("cluster", "name"); SshCredentials credentials = SshCredentials.builder() .username(config.get("ssh", "username")) .privateKey(readFile(config.get("ssh", "privateKey"))) .port(22) .build(); Map<String, String> properties = new HashMap<String, String>(); properties.put("accessKeyId", config.get("provider", "accessKeyId")); properties.put("secretAccessKey", config.get("provider", "secretAccessKey")); properties.put("region", config.get("provider", "region")); InstanceProviderConfig provider = InstanceProviderConfig.builder() .type(config.get("provider", "type")) .config(properties) .build(); Environment environment = Environment.builder() .name(clusterName + " Environment") .credentials(credentials) .provider(provider) .build(); EnvironmentsApi api = new EnvironmentsApi(client); try { api.create(environment); } catch (ApiException e) { if (e.getCode() == 409 /* conflict */) { System.out.println("Warning: an environment with the same name already exists"); } else { throw e; } } System.out.printf("Environments: %s%n", api.list()); return environment.getName(); }
Example 20
Source File: CreateClustersSample.java From director-sdk with Apache License 2.0 | 4 votes |
/** * Create a new CDH cluster with data from the configuration file. */ private String createCluster(ApiClient client, String environmentName, String deploymentName, Ini config) throws ApiException { String clusterName = config.get("cluster", "name"); int clusterSize = Integer.parseInt(config.get("cluster", "size")); // Create the master group Map<String, List<String>> masterRoles = new HashMap<String, List<String>>(); masterRoles.put("HDFS", Arrays.asList("NAMENODE", "SECONDARYNAMENODE")); masterRoles.put("YARN", Arrays.asList("RESOURCEMANAGER", "JOBHISTORY")); Map<String, VirtualInstanceGroup> groups = new HashMap<String, VirtualInstanceGroup>(); groups.put("masters", VirtualInstanceGroup.builder() .name("masters") .minCount(1) .serviceTypeToRoleTypes(masterRoles) .virtualInstances(Arrays.asList(createVirtualInstanceWithRandomId(config, "master"))) .build()); // Create the workers group Map<String, List<String>> workerRoles = new HashMap<String, List<String>>(); workerRoles.put("HDFS", Arrays.asList("DATANODE")); workerRoles.put("YARN", Arrays.asList("NODEMANAGER")); List<VirtualInstance> workerVirtualInstances = new ArrayList<VirtualInstance>(); for (int i = 0; i < clusterSize; i++) { workerVirtualInstances.add(createVirtualInstanceWithRandomId(config, "worker")); } groups.put("workers", VirtualInstanceGroup.builder() .name("workers") .minCount(clusterSize) .serviceTypeToRoleTypes(workerRoles) .virtualInstances(workerVirtualInstances) .build()); // Create the cluster template ClusterTemplate template = ClusterTemplate.builder() .name(clusterName) .productVersions(newMap("CDH", config.get("cluster", "cdh_version"))) .services(Arrays.asList("HDFS", "YARN")) .virtualInstanceGroups(groups) .build(); ClustersApi api = new ClustersApi(client); try { api.create(environmentName, deploymentName, template); } catch (ApiException e) { if (e.getCode() == 409 /* conflict */) { System.out.println("Warning: a cluster with the same name already exists"); } else { throw e; } } System.out.printf("Clusters: %s%n", api.list(environmentName, deploymentName)); return template.getName(); }