本文整理汇总了Java中org.ini4j.Ini类的典型用法代码示例。如果您正苦于以下问题:Java Ini类的具体用法?Java Ini怎么用?Java Ini使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ini类属于org.ini4j包,在下文中一共展示了Ini类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServerGroup
import org.ini4j.Ini; //导入依赖的package包/类
/**
* Returns the section from the <b>servers</b> config file used by the Subversion module which
* is holding the proxy settings for the given host
*
* @param host the host
* @return the section holding the proxy settings for the given host
*/
private Ini.Section getServerGroup(String host) {
if(host == null || host.equals("")) { // NOI18N
return null;
}
Ini.Section groups = svnServers.get(GROUPS_SECTION);
if(groups != null) {
for (Iterator<String> it = groups.keySet().iterator(); it.hasNext();) {
String key = it.next();
String value = groups.get(key);
if(value != null) {
value = value.trim();
if(value != null && match(value, host)) {
return svnServers.get(key);
}
}
}
}
return null;
}
示例2: setSSLCert
import org.ini4j.Ini; //导入依赖的package包/类
private boolean setSSLCert(RepositoryConnection rc, Ini.Section nbGlobalSection) {
if(rc == null) {
return false;
}
String certFile = rc.getCertFile();
if(certFile == null || certFile.equals("")) {
return false;
}
char[] certPasswordChars = rc.getCertPassword();
String certPassword = certPasswordChars == null ? "" : new String(certPasswordChars); //NOI18N
if(certPassword.equals("")) { // NOI18N
return false;
}
nbGlobalSection.put("ssl-client-cert-file", certFile);
if (!DO_NOT_SAVE_PASSPHRASE) {
nbGlobalSection.put("ssl-client-cert-password", certPassword);
return true;
}
return false;
}
示例3: merge
import org.ini4j.Ini; //导入依赖的package包/类
/**
* 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));
}
}
}
}
示例4: isSubsetOf
import org.ini4j.Ini; //导入依赖的package包/类
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));
}
}
}
示例5: storeIni
import org.ini4j.Ini; //导入依赖的package包/类
private void storeIni(Ini ini, String iniFile) {
assert initException == null;
BufferedOutputStream bos = null;
try {
String filePath;
if (dir != null) {
filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + iniFile; // NOI18N
} else {
filePath = getUserConfigPath() + iniFile;
}
File file = FileUtil.normalizeFile(new File(filePath));
file.getParentFile().mkdirs();
ini.store(bos = new BufferedOutputStream(new FileOutputStream(file)));
} catch (IOException ex) {
Mercurial.LOG.log(Level.INFO, null, ex);
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException ex) {
Mercurial.LOG.log(Level.INFO, null, ex);
}
}
}
}
示例6: getPicUrl
import org.ini4j.Ini; //导入依赖的package包/类
private String getPicUrl(String filename)
{
String url = null;
Ini ini = new Ini();
String filepath = configData.coolqDir + "/data/image/" + filename + ".cqimg";
try
{
ini.load(new FileReader(filepath));
} catch (IOException e)
{
e.printStackTrace();
}
Ini.Section section = ini.get("image");
url = section.get("url");
return url;
}
示例7: init
import org.ini4j.Ini; //导入依赖的package包/类
public static void init(String configFile) {
try {
Ini ini = new Ini(new File(configFile));
serverPort = Integer.parseInt(ini.get("global", "serverPort"));
prefixModeOnly = Boolean.parseBoolean(ini.get("index", "prefixModeOnly"));
indexFolderName = Boolean.parseBoolean(ini.get("index", "indexFolderName"));
useParallelPicturesGeneration = Boolean.parseBoolean(ini.get("thumbnail", "useParallelPicturesGeneration"));
forceExifToolsDownload = Boolean.parseBoolean(ini.get("global", "forceExifToolsDownload"));
forceExifToolsDownload = Boolean.parseBoolean(ini.get("global", "forceExifToolsDownload"));
addressElementsCount = Integer.parseInt(ini.get("global", "addressElementsCount"));
fullScreenPictureQuality = Integer.parseInt(ini.get("fullscreen", "fullScreenPictureQuality"));
maxFullScreenPictureWitdh = Integer.parseInt(ini.get("fullscreen", "maxFullScreenPictureWitdh"));
maxFullScreenPictureHeight = Integer.parseInt(ini.get("fullscreen", "maxFullScreenPictureHeight"));
thumbnailHeight = Integer.parseInt(ini.get("thumbnail", "thumbnailHeight"));
thumbnailQuality = Integer.parseInt(ini.get("thumbnail", "thumbnailQuality"));
} catch (Exception ex) {
throw new IllegalArgumentException("Incorrect config file : " + configFile + " - " + ex);
}
}
示例8: write
import org.ini4j.Ini; //导入依赖的package包/类
/**
* Write the object to a Writer.
*
* @param out
* Stream to write object out to.
*/
public void write(Writer out) throws IOException {
Ini configIni = new Ini();
Section section = configIni.add(SECTION_NAME);
section.put("algorithm", algorithm.toString());
section.put("provider", provider);
section.put("destination", destination.toString());
if (destinationTable != null) {
section.put("table", destinationTable);
}
if (defaultVisibility != null) {
section.put("defaultVisibility", new String(defaultVisibility, VISIBILITY_CHARSET));
}
configIni.store(out);
}
示例9: testWithEmptyOption
import org.ini4j.Ini; //导入依赖的package包/类
@Test public void testWithEmptyOption() throws Exception
{
Config cfg = new Config();
cfg.setEmptyOption(true);
Ini ini = new Ini();
Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL);
sec.put(Dwarf.PROP_FORTUNE_NUMBER, null);
ini.setConfig(cfg);
IniHandler handler = EasyMock.createMock(IniHandler.class);
handler.startIni();
handler.startSection(Dwarfs.PROP_BASHFUL);
handler.handleOption(Dwarf.PROP_FORTUNE_NUMBER, "");
handler.endSection();
handler.endIni();
EasyMock.replay(handler);
verify(ini, handler);
}
示例10: testWithStrictOperator
import org.ini4j.Ini; //导入依赖的package包/类
@Test public void testWithStrictOperator() throws Exception
{
Config cfg = new Config();
cfg.setStrictOperator(true);
Ini ini = new Ini();
Ini.Section sec = ini.add(Dwarfs.PROP_BASHFUL);
sec.put(Dwarf.PROP_AGE, DwarfsData.bashful.age);
ini.setConfig(cfg);
StringWriter writer = new StringWriter();
ini.store(writer);
StringBuilder exp = new StringBuilder();
exp.append(IniParser.SECTION_BEGIN);
exp.append(Dwarfs.PROP_BASHFUL);
exp.append(IniParser.SECTION_END);
exp.append(NL);
exp.append(Dwarf.PROP_AGE);
exp.append('=');
exp.append(DwarfsData.bashful.age);
exp.append(NL);
exp.append(NL);
assertEquals(exp.toString(), writer.toString());
}
示例11: test
import org.ini4j.Ini; //导入依赖的package包/类
private void test(String filename, String defaultEncoding) throws Exception
{
Charset charset = (defaultEncoding == null) ? Config.DEFAULT_FILE_ENCODING : Charset.forName(defaultEncoding);
UnicodeInputStreamReader reader = new UnicodeInputStreamReader(getClass().getResourceAsStream(filename), charset);
Ini ini = new Ini();
ini.setConfig(Config.getGlobal().clone());
ini.getConfig().setFileEncoding(charset);
ini.load(reader);
Ini.Section sec = ini.get("section");
if (sec == null)
{
throw new IllegalStateException("Missing section: section");
}
if (!"value".equals(sec.get("option")))
{
throw new IllegalStateException("Missing option: option");
}
}
示例12: sample01
import org.ini4j.Ini; //导入依赖的package包/类
void sample01(Ini ini)
{
Ini.Section section = ini.get("happy");
//
// read some values
//
String age = section.get("age");
String weight = section.get("weight");
String homeDir = section.get("homeDir");
//
// .. or just use java.util.Map interface...
//
Map<String, String> map = ini.get("happy");
age = map.get("age");
weight = map.get("weight");
homeDir = map.get("homeDir");
// get all section names
Set<String> sectionNames = ini.keySet();
//}
Helper.assertEquals(DwarfsData.happy, section.as(Dwarf.class));
}
示例13: sample04
import org.ini4j.Ini; //导入依赖的package包/类
void sample04(Ini ini)
{
Ini.Section sneezy = ini.get("sneezy");
String n1 = sneezy.get("fortuneNumber", 0); // = 11
String n2 = sneezy.get("fortuneNumber", 1); // = 22
String n3 = sneezy.get("fortuneNumber", 2); // = 33
String n4 = sneezy.get("fortuneNumber", 3); // = 44
// ok, lets do in it easier...
int[] n = sneezy.getAll("fortuneNumber", int[].class);
//}
// #2817399
assertEquals("11", n1);
assertEquals("22", n2);
assertEquals("33", n3);
assertEquals("44", n4);
assertEquals(4, n.length);
assertEquals(11, n[0]);
assertEquals(22, n[1]);
assertEquals(33, n[2]);
assertEquals(44, n[3]);
}
示例14: sample01
import org.ini4j.Ini; //导入依赖的package包/类
void sample01(Ini.Section section)
{
//
// read some values
//
String age = section.get("age");
String weight = section.get("weight");
String homeDir = section.get("homeDir");
// get all option names
Set<String> optionNames = section.keySet();
//}
assertEquals(String.valueOf(DwarfsData.happy.age), age);
assertEquals(String.valueOf(DwarfsData.happy.weight), weight);
assertEquals(String.valueOf(DwarfsData.happy.homeDir), homeDir);
}
示例15: run
import org.ini4j.Ini; //导入依赖的package包/类
@Override protected void run(File arg) throws Exception
{
Ini ini = new Ini(arg.toURI().toURL());
sample01(ini);
sample02(ini);
sample03(ini);
sample04(arg.toURI().toURL());
Options opts = new Options();
opts.putAll(ini.get(Dwarfs.PROP_BASHFUL));
sample05(opts);
//
File optFile = new File(arg.getParentFile(), OptTutorial.FILENAME);
sample06(optFile.toURI().toURL());
}