📄 inifileloader.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: INIFileLoader.java
package jit.util.jitca.ini;
import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;
public class INIFileLoader
{
private static final String SPLIT_STR = "=";
private HashMap section;
public INIFileLoader()
{
}
public HashMap loadIniFromFile(File file)
throws Exception
{
FileInputStream fis = new FileInputStream(file);
HashMap result = loadIniFromStream(fis);
fis.close();
return result;
}
public HashMap loadIniFromStream(InputStream is)
throws Exception
{
InputStreamReader ireader = new InputStreamReader(is);
BufferedReader breader = new BufferedReader(ireader);
section = new HashMap();
String strSection = null;
String strKey = null;
String strLine = null;
strLine = readLineIgnoreBlank(breader);
if(strLine == null)
return section;
if(!isSection(strLine))
throw new Exception("INI file's format error.");
for(; strLine != null; strLine = readLineIgnoreBlank(breader))
{
if(isSection(strLine))
{
strSection = getSection(strLine);
section.put(strSection, new HashMap());
continue;
}
if(isKey(strLine))
{
strKey = getKey(strLine);
String value = getValue(strLine);
((HashMap)section.get(strSection)).put(strKey, value);
continue;
}
if(isContinueValue(strLine))
{
StringBuffer buf = new StringBuffer();
String bef = (String)((HashMap)section.get(strSection)).get(strKey);
buf.append(bef);
buf.append(strLine.substring(2, strLine.length()));
((HashMap)section.get(strSection)).remove(strKey);
((HashMap)section.get(strSection)).put(strKey, buf.toString());
} else
{
throw new Exception("INI file load error.");
}
}
breader.close();
ireader.close();
return section;
}
private String getSection(String str)
{
if(str == null)
return null;
if(str.indexOf("[") != 0)
return null;
if(!str.endsWith("]"))
{
return null;
} else
{
StringTokenizer st = new StringTokenizer(str, "[]");
return st.nextToken();
}
}
private String getKey(String str)
{
if(str == null)
return null;
if(str.indexOf("->") == 0)
return null;
else
return str.substring(0, str.indexOf("="));
}
private String getValue(String str)
{
if(str == null)
return null;
else
return str.substring(str.indexOf("=") + 1, str.length());
}
private boolean isSection(String str)
{
return getSection(str) != null;
}
private boolean isKey(String str)
{
return getKey(str) != null;
}
private boolean isContinueValue(String str)
{
return str.indexOf("->") == 0;
}
private String readLineIgnoreBlank(BufferedReader in)
throws Exception
{
String result = null;
do
{
result = in.readLine();
if(result == null)
return null;
} while(result.trim().length() == 0);
return result.trim();
}
static
{
SPLIT_STR = "=";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -