//------------------------------------------------------------------------- /// <summary> /// Parses the specified source as an INI file. /// <para> /// This parses the specified character source expecting an INI file format. /// The resulting instance can be queried for each section in the file. /// </para> /// <para> /// INI files sometimes contain a Unicode Byte Order Mark. /// Callers are responsible for handling this, such as by using <seealso cref="UnicodeBom"/>. /// /// </para> /// </summary> /// <param name="source"> the INI file resource </param> /// <returns> the INI file </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public static IniFile of(CharSource source) { ArgChecker.notNull(source, "source"); ImmutableList <string> lines = Unchecked.wrap(() => source.readLines()); ImmutableMap <string, ImmutableListMultimap <string, string> > parsedIni = parse(lines); ImmutableMap.Builder <string, PropertySet> builder = ImmutableMap.builder(); parsedIni.forEach((sectionName, sectionData) => builder.put(sectionName, PropertySet.of(sectionData))); return(new IniFile(builder.build())); }