Top Description Fields Constructors Methods
de.siegmar.fastcsv.reader

public abstract Class AbstractBaseCsvCallbackHandler<T>

extends CsvCallbackHandler<T>
Class Inheritance
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.

Field Summary

Modifier and TypeField and Description
private int
private RecordType
private long

Constructor Summary

AccessConstructor and Description
protected
AbstractBaseCsvCallbackHandler()

Constructs a new instance.

Method Summary

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

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.addField.

Called for each field in the record.

protected final void
beginRecord(final long startingLineNumber)

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.beginRecord.

Called at the beginning of each record.

protected int

Returns:

the number of fields in the current record.
getFieldCount
()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.getFieldCount.

Returns the number of fields in the current record.

protected RecordType
getRecordType()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.getRecordType.

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

protected long

Returns:

the starting line number of the current record
getStartingLineNumber
()

The starting line number of the current record.

protected void
handleBegin(final long
the line number where the record starts (starting with 1)
startingLineNumber
)

Handles the beginning of a record.

protected void
handleComment(final char[]
the internal buffer that contains the field value (among other data)
buf
,
final int
the offset of the field value in the buffer
offset
,
final int
the length of the field value
len
)

Handles a comment.

protected void
handleEmpty()

Handles an empty line.

protected void
handleField(final int
the index of the field in the record (starting with 0)
fieldIdx
,
final char[]
the internal buffer that contains the field value (among other data)
buf
,
final int
the offset of the field value in the buffer
offset
,
final int
the length of the field value
len
,
final boolean
true if the field was quoted
quoted
)

Handles a field.

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

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.setComment.

Called for each comment line.

protected final void
setEmpty()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.setEmpty.

Called for each empty line.

Inherited from de.siegmar.fastcsv.reader.CsvCallbackHandler:
buildRecordterminate

Field Detail

fieldCountback to summary
private int fieldCount
recordTypeback to summary
private RecordType recordType
startingLineNumberback to summary
private long startingLineNumber

Constructor Detail

AbstractBaseCsvCallbackHandlerback to summary
protected AbstractBaseCsvCallbackHandler()

Constructs a new instance.

Method Detail

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

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.addField.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.addField.

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.

Annotations
@Override
beginRecordback to summary
protected final void beginRecord(final long startingLineNumber)

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.beginRecord.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.beginRecord.

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).

Annotations
@SuppressWarnings:checkstyle:HiddenField
@Override
getFieldCountback to summary
protected int getFieldCount()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.getFieldCount.

Returns the number of fields in the current record.

Returns:int

the number of fields in the current record.

Annotations
@Override
getRecordTypeback to summary
protected RecordType getRecordType()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.getRecordType.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.getRecordType.

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

The CsvReader will skip

Annotations
@Override
getStartingLineNumberback to summary
protected long getStartingLineNumber()

The starting line number of the current record.

See beginRecord(long) and getStartingLineNumber().

Returns:long

the starting line number of the current record

handleBeginback to summary
protected void handleBegin(final long startingLineNumber)

Handles the beginning of a record.

This method is called at the beginning of each record.

Parameters
startingLineNumber:long

the line number where the record starts (starting with 1)

Annotations
@SuppressWarnings:checkstyle:HiddenField
handleCommentback to summary
protected void handleComment(final char[] buf, final int offset, final 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:char[]

the internal buffer that contains the field value (among other data)

offset:int

the offset of the field value in the buffer

len:int

the length of the field value

handleEmptyback to summary
protected void handleEmpty()

Handles an empty line.

This method is called for each empty line.

handleFieldback to summary
protected void handleField(final int fieldIdx, final char[] buf, final int offset, final int len, final 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:int

the index of the field in the record (starting with 0)

buf:char[]

the internal buffer that contains the field value (among other data)

offset:int

the offset of the field value in the buffer

len:int

the length of the field value

quoted:boolean

true if the field was quoted

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

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.setComment.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.setComment.

Called for each comment line.

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

This method is not called if de.siegmar.fastcsv.reader.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.

Annotations
@Override
setEmptyback to summary
protected final void setEmpty()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.setEmpty.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.setEmpty.

Called for each empty line.

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

Annotations
@Override