/** * Obtains an instance, specifying the map of section to properties. * * @param sectionMap the map of sections * @return the INI file */ public static IniFile of(Map<String, PropertySet> sectionMap) { return new IniFile(ImmutableMap.copyOf(sectionMap)); }
/** * Parses the specified source as an INI file. * <p> * This parses the specified character source expecting an INI file format. * The resulting instance can be queried for each section in the file. * <p> * INI files sometimes contain a Unicode Byte Order Mark. * Callers are responsible for handling this, such as by using {@link UnicodeBom}. * * @param source the INI file resource * @return the INI file * @throws UncheckedIOException if an IO exception occurs * @throws IllegalArgumentException if the file cannot be parsed */ 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()); }