Class AbstractBaseCsvCallbackHandler<T>
- Type Parameters:
T- the type of the record
Base class for CsvCallbackHandler implementations that handles their own field storage and record building.
This implementation is stateful and must not be reused.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddField(char[] buf, int offset, int len, boolean quoted) Called for each field in the record.protected final voidbeginRecord(long startingLineNumber) Called at the beginning of each record.protected intReturns the number of fields in the current record..protected longThe starting line number of the current record.protected voidhandleBegin(long startingLineNumber) Handles the beginning of a record.protected voidhandleComment(char[] buf, int offset, int len) Handles a comment.protected voidhandleField(int fieldIdx, char[] buf, int offset, int len, boolean quoted) Handles a field.protected booleanReturns whether the current record is a comment..protected booleanReturns whether the current record is an empty line..protected final voidsetComment(char[] buf, int offset, int len) Called for each comment line.protected RecordWrapper<T> wrapRecord(T record) Builds a wrapper for the record that contains information necessary for theCsvReaderin order to determine how to process the record.Methods inherited from class de.siegmar.fastcsv.reader.CsvCallbackHandler
buildRecord, terminate
-
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)andgetStartingLineNumber().- Returns:
- the starting line number of the current record
-
isComment
protected boolean isComment()Returns whether the current record is a comment..- Returns:
- whether the current record is a comment.
-
isEmptyLine
protected boolean isEmptyLine()Returns whether the current record is an empty line..- Returns:
- whether the current record is an empty line.
-
getFieldCount
protected int getFieldCount()Returns the number of fields in the current record..- Returns:
- the number of fields in the current record.
-
beginRecord
protected final void beginRecord(long startingLineNumber) Called at the beginning of each record.
The
startingLineNumberis the line number where the record starts (starting with 1).Resets the internal state of this handler and delegates to
handleBegin(long).- Specified by:
beginRecordin classCsvCallbackHandler<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
quotedparameter indicates whether the field was quoted. It is for informational purposes only. Any potential escape characters are already removed and theoffsetpoints to the first character after the opening quote and thelendoes 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 betweennulland empty fields (foo,,barvs.foo,"",bar).The
bufparameter 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)after updating theemptyLineflag and before incrementing thefieldCount.- Specified by:
addFieldin classCsvCallbackHandler<T>- Parameters:
buf- the internal buffer that contains the field value (among other data)offset- the offset of the field value in the bufferlen- the length of the field valuequoted-trueif 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 bufferlen- the length of the field valuequoted-trueif 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 toCommentStrategy.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
bufparameter 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 thecommentandemptyLineflag and before incrementing thefieldCount.- Specified by:
setCommentin classCsvCallbackHandler<T>- Parameters:
buf- the internal buffer that contains the field value (among other data)offset- the offset of the field value in the bufferlen- 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 bufferlen- the length of the field value
-
wrapRecord
Builds a wrapper for the record that contains information necessary for theCsvReaderin order to determine how to process the record.- Parameters:
record- the actual record to be returned by theCsvReader, must not benull- Returns:
- the wrapper for the actual record
- Throws:
NullPointerException- ifnullis passed forrecord
-