/** * * @param args */ public static void main(String args[]) { boolean dbgFlag = true; iniFile inf = null; switch (args.length) { case 1: inf = new iniFile(null, args[0], dbgFlag); break; case 2: inf = new iniFile(args[0], args[1], dbgFlag); break; case 3: if (args[2].equalsIgnoreCase("false")) dbgFlag = false; inf = new iniFile(args[0], args[1], dbgFlag); break; default: System.err.println("Usage: test_iniFile [path] filename.ini [false]"); System.exit(1); } inf.printProps(System.out); }
/** * ********************************************************************** * Prints the iniFile. * * @param ps The <code>PrintStream</code> to which to print. */ public void printProps(PrintStream ps) { Enumeration se = getSectionList(); if (se == null) { ps.println(errMsg); } else { while (se.hasMoreElements()) { String sname = (String) se.nextElement(); setSection(sname); ps.println("[" + sname + "]"); Enumeration pe = getPropList(sname); while (pe.hasMoreElements()) { String pair[] = (String[]) pe.nextElement(); String prop = pair[0]; String valu = getProperty(prop); ps.println(" \"" + prop + "\" = \"" + valu + "\""); } } } } //************************************************************************
/** * ********************************************************************** * Create a <code>iniFile</code> object from the file named in the * parameter <code>fname</code>, and found on the parameter<code> path</code> * * @param path A <code>String</code> containing the path to the .ini file. * @param fname A <code>String</code> containing the name of the .ini file. * @param dbg A <code>boolean</code> that toggles debugging output. */ public iniFile(String path, String fname, boolean dbg) { Debug = dbg; if(path == null) path = System.getProperty("user.home"); String fileSeperator = System.getProperty("file.separator"); iniFile = path + fileSeperator + fname; errMsg = "The file: \"" + iniFile + "\" did not contain recognizable init information."; currentSection = -1; sectionNames = null; sectionProperties = null; parseFile(); if(sectionNames == null) System.err.println(errMsg); } //************************************************************************
/** * ********************************************************************** * Prints the iniFile. * * @param ps The <code>PrintStream</code> to which to print. */ public void printProps(PrintStream ps) { Enumeration se = getSectionList(); if(se == null) { ps.println(errMsg); } else { while(se.hasMoreElements()) { String sname = (String) se.nextElement(); setSection(sname); ps.println("[" + sname + "]"); Enumeration pe = getPropList(sname); while(pe != null && pe.hasMoreElements()) { String pair[] = (String[]) pe.nextElement(); String prop = pair[0]; String valu = getProperty(prop); ps.println(" \"" + prop + "\" = \"" + valu + "\""); } } } } //************************************************************************
/** * ********************************************************************** * Create a <code>iniFile</code> object from the file named in the * parameter <code>fname</code>, and found on the parameter<code> path</code> * * @param path A <code>String</code> containing the path to the .ini file. * @param fname A <code>String</code> containing the name of the .ini file. * @param dbg A <code>boolean</code> that toggles debugging output. */ public iniFile(String path, String fname, boolean dbg) { Debug = dbg; if (path == null) path = System.getProperty("user.home"); String fileSeperator = System.getProperty("file.separator"); iniFile = path + fileSeperator + fname; errMsg = "The file: \"" + iniFile + "\" did not contain recognizable init information."; currentSection = -1; sectionNames = null; sectionProperties = null; parseFile(); if (sectionNames == null) System.err.println(errMsg); } //************************************************************************
/** * @param args */ public static void main(String args[]) { boolean dbgFlag = true; iniFile inf = null; switch (args.length) { case 1: inf = new iniFile(null, args[0], dbgFlag); break; case 2: inf = new iniFile(args[0], args[1], dbgFlag); break; case 3: if(args[2].equalsIgnoreCase("false")) dbgFlag = false; inf = new iniFile(args[0], args[1], dbgFlag); break; default: System.err.println("Usage: test_iniFile [path] filename.ini [false]"); System.exit(1); } inf.printProps(System.out); }