Class IndexedCsvReader.IndexedCsvReaderBuilder

  • Enclosing class:
    IndexedCsvReader<T>

    public static final class IndexedCsvReader.IndexedCsvReaderBuilder
    extends java.lang.Object
    This builder is used to create configured instances of IndexedCsvReader. The default configuration of this class adheres with RFC 4180.

    The line delimiter (line-feed, carriage-return or the combination of both) is detected automatically and thus not configurable.

    • Field Detail

      • fieldSeparator

        private char fieldSeparator
      • quoteCharacter

        private char quoteCharacter
      • commentCharacter

        private char commentCharacter
      • acceptCharsAfterQuotes

        private boolean acceptCharsAfterQuotes
      • pageSize

        private int pageSize
    • Constructor Detail

      • IndexedCsvReaderBuilder

        private IndexedCsvReaderBuilder()
    • Method Detail

      • fieldSeparator

        public IndexedCsvReader.IndexedCsvReaderBuilder fieldSeparator​(char fieldSeparator)
        Sets the fieldSeparator used when reading CSV data.
        Parameters:
        fieldSeparator - the field separator character (default: , - comma).
        Returns:
        This updated object, allowing additional method calls to be chained together.
      • quoteCharacter

        public IndexedCsvReader.IndexedCsvReaderBuilder quoteCharacter​(char quoteCharacter)
        Sets the quoteCharacter used when reading CSV data.
        Parameters:
        quoteCharacter - the character used to enclose fields (default: " - double quotes).
        Returns:
        This updated object, allowing additional method calls to be chained together.
      • commentCharacter

        public IndexedCsvReader.IndexedCsvReaderBuilder commentCharacter​(char commentCharacter)
        Sets the commentCharacter used to comment lines.
        Parameters:
        commentCharacter - the character used to comment lines (default: # - hash)
        Returns:
        This updated object, allowing additional method calls to be chained together.
        See Also:
        commentStrategy(CommentStrategy)
      • acceptCharsAfterQuotes

        public IndexedCsvReader.IndexedCsvReaderBuilder acceptCharsAfterQuotes​(boolean acceptCharsAfterQuotes)
        Specifies whether the presence of characters between a closing quote and a field separator or the end of a line should be treated as an error or not.

        Example:

         "a"b,"c"
         

        If this is set to true, the value ab will be returned for the first field.

        If this is set to false, a CsvParseException will be thrown.

        Parameters:
        acceptCharsAfterQuotes - allow characters after quotes (default: true).
        Returns:
        This updated object, allowing additional method calls to be chained together.
      • statusListener

        public IndexedCsvReader.IndexedCsvReaderBuilder statusListener​(StatusListener statusListener)
        Sets the statusListener to listen for indexer status updates.
        Parameters:
        statusListener - the status listener.
        Returns:
        This updated object, allowing additional method calls to be chained together.
      • index

        public IndexedCsvReader.IndexedCsvReaderBuilder index​(CsvIndex csvIndex)
        Sets a prebuilt index that should be used for accessing the file.
        Parameters:
        csvIndex - a prebuilt index
        Returns:
        This updated object, allowing additional method calls to be chained together.
      • checkControlCharacter

        private static void checkControlCharacter​(char controlChar)
      • ofCsvRecord

        public IndexedCsvReader<CsvRecord> ofCsvRecord​(java.nio.file.Path file)
                                                throws java.io.IOException
        Constructs a new IndexedCsvReader of CsvRecord for the specified path using UTF-8 as the character set.

        Convenience method for build(CsvCallbackHandler, Path, Charset) with CsvRecordHandler as the callback handler and StandardCharsets.UTF_8 as the charset.

        Parameters:
        file - the file to read data from.
        Returns:
        a new IndexedCsvReader - never null. Remember to close it!
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.NullPointerException - if file or charset is null
      • ofCsvRecord

        public IndexedCsvReader<CsvRecord> ofCsvRecord​(java.nio.file.Path file,
                                                       java.nio.charset.Charset charset)
                                                throws java.io.IOException
        Constructs a new IndexedCsvReader of CsvRecord for the specified arguments.

        Convenience method for build(CsvCallbackHandler, Path, Charset) with CsvRecordHandler as the callback handler.

        Parameters:
        file - the file to read data from.
        charset - the character set to use.
        Returns:
        a new IndexedCsvReader - never null. Remember to close it!
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.NullPointerException - if file or charset is null
      • build

        public <T> IndexedCsvReader<T> build​(CsvCallbackHandler<T> callbackHandler,
                                             java.nio.file.Path file)
                                      throws java.io.IOException
        Constructs a new IndexedCsvReader for the specified callback handler and path using UTF-8 as the character set.

        Convenience method for build(CsvCallbackHandler, Path, Charset) with StandardCharsets.UTF_8 as charset.

        Type Parameters:
        T - the type of the CSV record.
        Parameters:
        callbackHandler - the callback handler to use.
        file - the file to read data from.
        Returns:
        a new IndexedCsvReader - never null. Remember to close it!
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.NullPointerException - if callbackHandler, file or charset is null
      • build

        public <T> IndexedCsvReader<T> build​(CsvCallbackHandler<T> callbackHandler,
                                             java.nio.file.Path file,
                                             java.nio.charset.Charset charset)
                                      throws java.io.IOException
        Constructs a new IndexedCsvReader for the specified arguments.
        Type Parameters:
        T - the type of the CSV record.
        Parameters:
        callbackHandler - the callback handler to use.
        file - the file to read data from.
        charset - the character set to use.
        Returns:
        a new IndexedCsvReader - never null. Remember to close it!
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.lang.NullPointerException - if callbackHandler, file or charset is null