Class AbstractBaseCsvCallbackHandler<T>

java.lang.Object
de.siegmar.fastcsv.reader.CsvCallbackHandler<T>
de.siegmar.fastcsv.reader.AbstractBaseCsvCallbackHandler<T>
Type Parameters:
T - the type of the record

public abstract class AbstractBaseCsvCallbackHandler<T> extends CsvCallbackHandler<T>

Base class for CsvCallbackHandler implementations that handles their own field storage and record building.

This implementation is stateful and must not be reused.

  • Constructor Details

    • AbstractBaseCsvCallbackHandler

      protected AbstractBaseCsvCallbackHandler()
      Constructs a new instance.
  • Method Details

    • getStartingLineNumber

      protected long getStartingLineNumber()

      The starting line number of the current record.

      See beginRecord(long) and getStartingLineNumber().

      Returns:
      the starting line number of the current record
    • getRecordType

      protected RecordType getRecordType()

      Returns the type of the record that is built from the CSV data.

      The CsvReader will skip

      Specified by:
      getRecordType in class CsvCallbackHandler<T>
      Returns:
      the type of the record that is built from the CSV data
    • getFieldCount

      protected int getFieldCount()
      Returns the number of fields in the current record..
      Specified by:
      getFieldCount in class CsvCallbackHandler<T>
      Returns:
      the number of fields in the current record.
    • beginRecord

      protected final void beginRecord(long startingLineNumber)

      Called at the beginning of each record.

      The startingLineNumber is the line number where the record starts (starting with 1).

      Resets the internal state of this handler and delegates to handleBegin(long).

      Specified by:
      beginRecord in class CsvCallbackHandler<T>
      Parameters:
      startingLineNumber - the line number where the record starts (starting with 1)
    • handleBegin

      protected void handleBegin(long startingLineNumber)

      Handles the beginning of a record.

      This method is called at the beginning of each record.

      Parameters:
      startingLineNumber - the line number where the record starts (starting with 1)
    • addField

      protected final void addField(char[] buf, int offset, int len, boolean quoted)

      Called for each field in the record.

      A record can either be a comment or a regular record. If this method is called, the record is a regular record and cannot be a comment.

      The quoted parameter indicates whether the field was quoted. It is for informational purposes only. Any potential escape characters are already removed and the offset points to the first character after the opening quote and the len does not include the closing quote. Hence, a quoted field can be processed in the same way as an unquoted field. Some implementations need the information whether a field was quoted, e.g., for differentiating between null and empty fields (foo,,bar vs. foo,"",bar).

      The buf parameter is the internal buffer that contains the field value (among other data). Do not attempt to modify the buffer or store a reference to it. The buffer is reused for performance reasons.

      This implementation delegates to handleField(int, char[], int, int, boolean) before incrementing the fieldCount.

      Specified by:
      addField in class CsvCallbackHandler<T>
      Parameters:
      buf - the internal buffer that contains the field value (among other data)
      offset - the offset of the field value in the buffer
      len - the length of the field value
      quoted - true if the field was quoted
    • handleField

      protected void handleField(int fieldIdx, char[] buf, int offset, int len, boolean quoted)

      Handles a field.

      This method is called for each field in the record.

      See addField(char[],int,int,boolean) for more details on the parameters.

      Parameters:
      fieldIdx - the index of the field in the record (starting with 0)
      buf - the internal buffer that contains the field value (among other data)
      offset - the offset of the field value in the buffer
      len - the length of the field value
      quoted - true if the field was quoted
    • setComment

      protected final void setComment(char[] buf, int offset, int len)

      Called for each comment line.

      Note that the comment character is not included in the value.

      This method is not called if CsvReader.CsvReaderBuilder.commentStrategy(CommentStrategy) is set to CommentStrategy.NONE.

      There can only be one invocation of this method per record. A record can either be a comment or a regular record. If this method is called, the record is a comment and cannot be a regular record.

      The buf parameter is the internal buffer that contains the field value (among other data). Do not attempt to modify the buffer or store a reference to it. The buffer is reused for performance reasons.

      This implementation delegates to handleComment(char[],int,int) after updating the recordType and before incrementing the fieldCount.

      Specified by:
      setComment in class CsvCallbackHandler<T>
      Parameters:
      buf - the internal buffer that contains the field value (among other data)
      offset - the offset of the field value in the buffer
      len - the length of the field value
    • handleComment

      protected void handleComment(char[] buf, int offset, int len)

      Handles a comment.

      This method is called for each comment line.

      See setComment(char[],int,int) for more details on the parameters.

      Parameters:
      buf - the internal buffer that contains the field value (among other data)
      offset - the offset of the field value in the buffer
      len - the length of the field value
    • setEmpty

      protected final void setEmpty()

      Called for each empty line.

      This implementation delegates to handleEmpty() after updating the recordType and before setting the fieldCount to 1.

      Specified by:
      setEmpty in class CsvCallbackHandler<T>
    • handleEmpty

      protected void handleEmpty()

      Handles an empty line.

      This method is called for each empty line.