org.ini4j.Wini Java Examples

The following examples show how to use org.ini4j.Wini. 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: SettingsFile.java    From citra_android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Writes the contents of a Section HashMap to disk.
 *
 * @param parser  A Wini pointed at a file on disk.
 * @param section A section containing settings to be written to the file.
 */
private static void writeSection(Wini parser, SettingSection section)
{
  // Write the section header.
  String header = section.getName();

  // Write this section's values.
  HashMap<String, Setting> settings = section.getSettings();
  Set<String> keySet = settings.keySet();

  for (String key : keySet)
  {
    Setting setting = settings.get(key);
    parser.put(header, setting.getKey(), setting.getValueAsString());
  }
}
 
Example #2
Source File: Config.java    From captain with Apache License 2.0 6 votes vote down vote up
public void save() throws IOException {
	if (this.inifile == null || this.inifile.isEmpty()) {
		return;
	}
	File f = new File(this.inifile);
	if (!f.exists()) {
		f.getParentFile().mkdirs();
		f.createNewFile();
	}
	Wini ini = new Wini(f);
	ini.put("server", "host", this.bindHost);
	ini.put("server", "port", this.bindPort);
	ini.put("server", "thread", this.threadNum);
	ini.put("redis", "host", this.redisHost);
	ini.put("redis", "port", this.redisPort);
	ini.put("redis", "db", this.redisDb);
	ini.put("watch", "interval", this.interval);
	ini.store();
}
 
Example #3
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * @param basePath  the base path to attach to, if relative file name is used
   * @param fileName  the name of the file to be loaded 
   * @param enableMultiOption  the state of multi-option configuration flag  
   */
private Ini loadFile ( String basePath, String fileName
                     , boolean enableMultiOption ) throws Exception 
{
    String full_name = FilenameUtils.concat(basePath, fileName);
    File file = new File(full_name); 
       if (file.exists() && file.isFile()) {
           Ini ini = new Wini();
           Config config = ini.getConfig();
           
           config.setMultiSection(true);
           config.setMultiOption(enableMultiOption);
           config.setGlobalSection(true);
           config.setComment(true);

           ini.setFile(file);
           ini.setComment(COMMENT_LINE_CHARS);
           try(InputStreamReader inputStreamReader = TextEncoding.getInputStreamReader(file)){
           	ini.load(inputStreamReader);
           }
           return ini;
       }
    return null;
}
 
Example #4
Source File: WebshellFeatures.java    From MonitorClient with Apache License 2.0 5 votes vote down vote up
public WebshellFeatures(){
    try {
        File file=new File("config/webshellFeatures.ini");
        if(file.exists()){
            ini=new Wini(file);
            MonitorClientApplication.log.info("load webshellFeatures.ini success");
        }else{
            MonitorClientApplication.log.error("load webshellFeatures.ini error");
        }
    } catch (IOException e) {
        e.printStackTrace();
        MonitorClientApplication.log.error("load webshellFeatures.ini error");
    }
}
 
Example #5
Source File: Config.java    From captain with Apache License 2.0 5 votes vote down vote up
public void load() throws IOException {
	if (this.inifile == null || this.inifile.isEmpty()) {
		return;
	}
	File f = new File(this.inifile);
	if (f.exists() && f.isFile()) {
		Wini ini = new Wini(f);
		String bindHost = ini.get("server", "host", String.class);
		Integer bindPort = ini.get("server", "port", Integer.class);
		Integer threadNum = ini.get("server", "thread", Integer.class);
		String redisHost = ini.get("redis", "host", String.class);
		Integer redisPort = ini.get("redis", "port", Integer.class);
		Integer redisDb = ini.get("redis", "db", Integer.class);
		Integer interval = ini.get("watch", "interval", Integer.class);
		if (bindHost != null) {
			this.bindHost = bindHost;
		}
		if (bindPort != null) {
			this.bindPort = bindPort;
		}
		if(threadNum != null) {
			this.threadNum = threadNum;
		}
		if (redisHost != null) {
			this.redisHost = redisHost;
		}
		if (redisPort != null) {
			this.redisPort = redisPort;
		}
		if (redisDb != null) {
			this.redisDb = redisDb;
		}
		if (interval != null) {
			this.interval = interval;
		}
	}
}
 
Example #6
Source File: ClientPermissionLoader.java    From protect with MIT License 4 votes vote down vote up
public static AccessEnforcement loadIniFile(final File iniFile) throws IOException {

		System.out.println("Loading client permissions: " + iniFile.toString());

		// Load ini file
		final Wini ini = new Wini(iniFile);

		// Create map of usernames to their permissions
		final ConcurrentMap<String, ClientPermissions> permissionMap = new ConcurrentHashMap<String, ClientPermissions>();

		// Create set of all known secrets
		final Set<String> knownSecrets = new HashSet<>();

		// Iterate over each section (each section is a secret)
		final Collection<Profile.Section> secretSections = ini.values();
		for (Profile.Section secretSection : secretSections) {

			// Update set of known secrets
			final String secretName = secretSection.getName();
			knownSecrets.add(secretName);

			// Each value in this section represents a user's permission to this secret
			for (final Entry<String, String> userPermission : secretSection.entrySet()) {
				final String username = userPermission.getKey();
				final String permissions = userPermission.getValue();

				// PRint username and secret
				//System.out.print(username + "." + secretName + "\t\t = ");
				
				// Parse permissions
				final String[] permissionArray = permissions.split(",");
				//System.out.println(Arrays.toString(permissionArray));

				// Add permissions from the comma-separated list
				permissionMap.putIfAbsent(username, new ClientPermissions());
				final ClientPermissions clientPermissions = permissionMap.get(username);
				for (final String permissionString : permissionArray) {
					// Sanitize string and convert to enumeration
					final Permissions permission = Permissions.valueOf(permissionString.trim().toUpperCase());
					clientPermissions.addPermission(secretName, permission);
				}
			}
		}

		return new AccessEnforcement(permissionMap, knownSecrets);
	}