Ini ini = new Ini(new File("/path/to/file")); System.out.println(ini.get("header", "key"));
void foo() { { Ini myIni = new Ini(new FileReader(myFile)); } myIni.get("toto"); //error here, since myIni is out of scope }
Ini myIni = null; try { myIni = new Ini(new FileReader(myFile)); } catch (IOException e) { e.printStackTrace(); } if( myIni != null ) { myIni.get("toto"); //access the rest of myIni } else { //handle initialization error }
Ini myIni = null; try { myIni = new Ini(new FileReader(myFile)); } catch (IOException e) { e.printStackTrace(); } if(myIni!=null){ myIni.get("toto"); }
//open the file Ini ini = new Ini(new File(iniFileName)); //load all values at once Ini.Section names = ini.get("mySectionX"); myStr[] = names.getAll("myKey1", String[].class);
try { Ini myIni = new Ini(new FileReader(myFile)); myIni.get("toto"); } catch (IOException e) { e.printStackTrace(); }
Ini myIni = null; try { myIni = new Ini(new FileReader(myFile)); } catch (IOException e) { e.printStackTrace(); throw new MyCustomInitFailedException(); //throw any exception that might be appropriate, possibly wrapping e } myIni.get("toto");
try { Ini myIni= new Ini(new FileReader(myFile)); myIni.get("toto"); } catch (IOException e) { e.printStackTrace(); }
Ini myIni = null; try { myIni = new Ini(new FileReader(myFile)); } catch (IOException e) { e.printStackTrace(); } myIni.get("toto");
@Override public void addConfiguration(Ini ini) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); for (GlobalFilterConfiguration globalFilterConfiguration : globalFilterConfigurations) { for (Map.Entry<String, Class<? extends AdviceFilter>> entry : globalFilterConfiguration.getGlobalFilters().entrySet()) { mainSection.put(entry.getKey(), entry.getValue().getName()); } } } }
Ini ini = new Ini(new File("/path/to/file")); System.out.println(ini.get("header", "key"));
Ini ini = new Ini(new File("/path/to/file")); System.out.println(ini.get("HEADING1/SUBHEADING", "DBUSer"));
private void configureSessionStorageEvaluator(Ini ini) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); mainSection.put("octopusSessionStorageEvaluator", OctopusSessionStorageEvaluator.class.getName()); mainSection.put("securityManager.subjectDAO.sessionStorageEvaluator", "$octopusSessionStorageEvaluator"); }
@Override public void addConfiguration(Ini ini) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); mainSection.put("OAuth2Matcher", OAuth2CredentialsMatcher.class.getName()); mainSection.put("credentialsMatcher.matcher", "$OAuth2Matcher"); } }
private void addAuthenticationListener(Ini ini) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); mainSection.put("OctopusAuthenticator", OctopusRealmAuthenticator.class.getName()); mainSection.put("securityManager.authenticator", "$OctopusAuthenticator"); }
import org.ini4j.Ini; import org.ini4j.Profile.Section; import java.io.FileReader; public class Test { public static void main(String[] args) throws Exception { Ini ini = new Ini(new FileReader("test.ini")); System.out.println("Number of sections: "+ini.size()+"\n"); for (String sectionName: ini.keySet()) { System.out.println("["+sectionName+"]"); Section section = ini.get(sectionName); for (String optionKey: section.keySet()) { System.out.println("\t"+optionKey+"="+section.get(optionKey)); } } } }
private void addHashedCredentialsConfig(Ini ini, String someHashAlgorithmName) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); mainSection.put("hashedMatcher", OctopusHashedCredentialsMatcher.class.getName()); mainSection.put("hashedMatcher.hashAlgorithmName", someHashAlgorithmName); if (config.getHashEncoding() != HashEncoding.HEX) { mainSection.put("hashedMatcher.storedCredentialsHexEncoded", "false"); } mainSection.put("hashedMatcher.hashIterations", String.valueOf(config.getHashIterations())); ConfigurationPluginHelper.addToList(ini, IniSecurityManagerFactory.MAIN_SECTION_NAME, "credentialsMatcher.matchers", "$hashedMatcher"); }
private void configureCache(Ini ini) { Ini.Section mainSection = ini.get(IniSecurityManagerFactory.MAIN_SECTION_NAME); mainSection.put("cacheManager", config.getCacheManager()); mainSection.put("appRealm.cacheManager", "$cacheManager"); mainSection.put("securityManager.cacheManager", "$cacheManager"); }
public static void addToList(Ini ini, String sectionName, String key, String value) { Ini.Section section = ini.get(sectionName); String currentValue = section.get(key); section.remove(key); // Otherwise the key stays on the same place in the list and references the new value too early if (currentValue == null) { section.put(key, value); } else { section.put(key, currentValue + "," + value); } } }
Ini ini = new Ini(); ini.setComment(" Main comment "); //comment about the file //add a section comment, a section and a value ini.putComment("mySectionX", " Comment about the section"); ini.put("mySectionX", "myKey1", "value1"); //adding many parameters at one in a section String[] keyList = {value1, value2, value3}; ini.add("mySectionY"); Ini.Section names = ini.get("mySectionY"); names.putAll("myKey1", keyList); //put all new elements at once ... ini.store(new File(iniFileName));