Java Code Examples for org.ini4j.Profile#Section

The following examples show how to use org.ini4j.Profile#Section . 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: WifImporter.java    From Jabit with Apache License 2.0 6 votes vote down vote up
public WifImporter(BitmessageContext ctx, InputStream in, Pubkey.Feature... features) throws IOException {
    this.ctx = ctx;

    Ini ini = new Ini();
    ini.load(in);

    for (Entry<String, Profile.Section> entry : ini.entrySet()) {
        if (!entry.getKey().startsWith("BM-"))
            continue;

        Profile.Section section = entry.getValue();
        BitmessageAddress address = Factory.createIdentityFromPrivateKey(
            entry.getKey(),
            getSecret(section.get("privsigningkey")),
            getSecret(section.get("privencryptionkey")),
            Long.parseLong(section.get("noncetrialsperbyte")),
            Long.parseLong(section.get("payloadlengthextrabytes")),
            Pubkey.Feature.bitfield(features)
        );
        if (section.containsKey("chan")) {
            address.setChan(Boolean.parseBoolean(section.get("chan")));
        }
        address.setAlias(section.get("label"));
        identities.add(address);
    }
}
 
Example 2
Source File: IniUtil.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
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 3
Source File: IniUtil.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
public static Map<String,String> parseIni(String sectionName,String string) {
    Ini ini = new Ini();
    try {
        ini.load(new StringReader(string));
        Profile.Section section = ini.get(sectionName);
        return section;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 4
Source File: IniEntity.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 获取指定部分指定键的值
 *
 * @param section 所属部分
 * @param key     属性(键)
 * @return String 键对应的值
 */
public String getCfgValue(String section, String key) throws Exception {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    String value = ps.get(key);
    if (StringUtils.isBlank(value)) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    return value;
}
 
Example 5
Source File: IniEntity.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 获取指定部分指定键指定值类型的值
 *
 * @param section      所属部分
 * @param key          属性(键)
 * @param defaultValue 值的类型
 * @return T 键对应的值
 */
public <T> T getCfgValue(String section, String key, T defaultValue) {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        return defaultValue;
    }
    String value = ps.get(key);
    if (StringUtils.isBlank(value)) {
        return defaultValue;
    }
    return getValueByType(value, defaultValue);
}
 
Example 6
Source File: IniEntity.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 获取Section对象
 *
 * @param section Section 键
 * @return Section
 */
public Profile.Section getSection(String section) throws Exception {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    return ps;
}
 
Example 7
Source File: IniEntity.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 获取所有的Section键
 *
 * @return List<String>
 */
public List<String> getSectionList() {
    Set<Map.Entry<String, Profile.Section>> entrySet = ini.entrySet();
    List<String> list = new ArrayList<>();
    for (Map.Entry<String, Profile.Section> entry : entrySet) {
        list.add(entry.getKey());
    }
    return list;
}
 
Example 8
Source File: IniEntity.java    From nuls with MIT License 5 votes vote down vote up
public String getCfgValue(String section, String key) throws Exception {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    String value = ps.get(key);
    if (StringUtils.isBlank(value)) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    return value;
}
 
Example 9
Source File: IniEntity.java    From nuls with MIT License 5 votes vote down vote up
public <T> T getCfgValue(String section, String key, T defaultValue) {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        return defaultValue;
    }
    String value = ps.get(key);
    if (StringUtils.isBlank(value)) {
        return defaultValue;
    }
    return getValueByType(value, defaultValue);
}
 
Example 10
Source File: IniEntity.java    From nuls with MIT License 5 votes vote down vote up
public Profile.Section getSection(String section) throws Exception {
    Profile.Section ps = ini.get(section);
    if (null == ps) {
        throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
    }
    return ps;
}
 
Example 11
Source File: IniEntity.java    From nuls with MIT License 5 votes vote down vote up
public List<String> getSectionList() {
    Set<Map.Entry<String, Profile.Section>> entrySet = ini.entrySet();
    List<String> list = new ArrayList<>();
    for (Map.Entry<String, Profile.Section> entry : entrySet) {
        list.add(entry.getKey());
    }
    return list;
}
 
Example 12
Source File: WifExporter.java    From Jabit with Apache License 2.0 5 votes vote down vote up
public WifExporter addIdentity(BitmessageAddress identity) {
    Profile.Section section = ini.add(identity.getAddress());
    section.add("label", identity.getAlias());
    section.add("enabled", true);
    section.add("decoy", false);
    if (identity.isChan()) {
        section.add("chan", identity.isChan());
    }
    section.add("noncetrialsperbyte", identity.getPubkey().getNonceTrialsPerByte());
    section.add("payloadlengthextrabytes", identity.getPubkey().getExtraBytes());
    section.add("privsigningkey", exportSecret(identity.getPrivateKey().getPrivateSigningKey()));
    section.add("privencryptionkey", exportSecret(identity.getPrivateKey().getPrivateEncryptionKey()));
    return this;
}
 
Example 13
Source File: GitTortoise.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
@NotNull
static GitTortoise parseConfig(@NotNull InputStream stream) throws IOException {
  @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Ini ini = new Ini(stream);
  final Map<String, String> result = new HashMap<>();
  for (Map.Entry<String, Profile.Section> sectionEntry : ini.entrySet()) {
    for (Map.Entry<String, String> configEntry : sectionEntry.getValue().entrySet()) {
      String value = configEntry.getValue();
      if (value.startsWith("\"") && value.endsWith("\"")) {
        value = value.substring(1, value.length() - 1);
      }
      result.put(sectionEntry.getKey() + ":" + configEntry.getKey(), value);
    }
  }
  return new GitTortoise(result.isEmpty() ? Collections.emptyMap() : result);
}
 
Example 14
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);
	}