/** * Parses the specified reader as a CSV file where the separator is specified and might not be a comma. * <p> * This factory method 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. * <p> * The caller is responsible for closing the reader, such as by calling {@link #close()}. * * @param reader the file reader * @param headerRow whether the source has a header row, an empty source must still contain the header * @param separator the separator used to separate each field, typically a comma, but a tab is sometimes used * @return the CSV file * @throws UncheckedIOException if an IO exception occurs * @throws IllegalArgumentException if the file cannot be parsed */ public static CsvIterator of(Reader reader, boolean headerRow, char separator) { ArgChecker.notNull(reader, "reader"); @SuppressWarnings("resource") BufferedReader breader = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); return create(breader, headerRow, separator); }
/** * Parses the specified source as a CSV file where the separator is specified and might not be a comma. * <p> * 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. * <p> * This method opens the CSV file for reading. * The caller is responsible for closing it by calling {@link #close()}. * * @param source the file resource * @param headerRow whether the source has a header row, an empty source must still contain the header * @param separator the separator used to separate each field, typically a comma, but a tab is sometimes used * @return the CSV file * @throws UncheckedIOException if an IO exception occurs * @throws IllegalArgumentException if the file cannot be parsed */ public static CsvIterator of(CharSource source, boolean headerRow, char separator) { ArgChecker.notNull(source, "source"); @SuppressWarnings("resource") BufferedReader reader = Unchecked.wrap(() -> source.openBufferedStream()); return create(reader, headerRow, separator); }