/// <summary> /// Parses the specified source as a CSV file where the separator is specified and might not be a comma. /// <para> /// This overload allows the separator to be controlled. /// For example, a tab-separated file is very similar to a CSV file, the only difference is the separator. /// </para> /// <para> /// CSV 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 file resource </param> /// <param name="headerRow"> whether the source has a header row, an empty source must still contain the header </param> /// <param name="separator"> the separator used to separate each field, typically a comma, but a tab is sometimes used </param> /// <returns> the CSV file </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public static CsvFile of(CharSource source, bool headerRow, char separator) { ArgChecker.notNull(source, "source"); IList <string> lines = Unchecked.wrap(() => source.readLines()); return(create(lines, headerRow, separator)); }
//------------------------------------------------------------------------- /// <summary> /// Parses the specified source as a properties file. /// <para> /// This parses the specified character source expecting a properties file format. /// The resulting instance can be queried for each key and value. /// </para> /// <para> /// Properties 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 properties file resource </param> /// <returns> the properties file </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public static PropertiesFile of(CharSource source) { ArgChecker.notNull(source, "source"); ImmutableList <string> lines = Unchecked.wrap(() => source.readLines()); PropertySet keyValues = parse(lines); return(new PropertiesFile(keyValues)); }
//------------------------------------------------------------------------- /// <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())); }