/** * Constructs new IniEditor instance with a common section, defining * comment delimiters. Options in the common section are used as defaults * for all other sections. * * @param commonName name of the common section * @param delims an array of characters to be recognized as starters of * comment lines; the first of them will be used for newly created * comments */ public IniEditor(String commonName, char[] delims, boolean isCaseSensitive) { this.sections = new HashMap<String, Section>(); this.sectionOrder = new LinkedList<String>(); this.isCaseSensitive = isCaseSensitive; if (commonName != null) { this.commonName = commonName; addSection(this.commonName); } this.commentDelims = delims; this.optionFormat = new OptionFormat(Section.DEFAULT_OPTION_FORMAT); }
/** * Loads INI formatted input from a stream reader into this instance. * Everything in the stream before the first section header is ignored. * * @param streamReader where to read from * @throws IOException at an I/O problem */ public void load(InputStreamReader streamReader) throws IOException { BufferedReader reader = new BufferedReader(streamReader); String curSection = null; String line = null; while (reader.ready()) { line = reader.readLine().trim(); if (line.length() > 0 && line.charAt(0) == Section.HEADER_START) { int endIndex = line.indexOf(Section.HEADER_END); if (endIndex >= 0) { curSection = line.substring(1, endIndex); addSection(curSection); } } if (curSection != null) { Section sect = getSection(curSection); sect.load(reader); } } }