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

public abstract sealed Class AbstractInternalCsvCallbackHandler<T>

extends CsvCallbackHandler<T>
permits CsvRecordHandler, NamedCsvRecordHandler, StringArrayHandler
Class Inheritance
Known Direct Subclasses
de.siegmar.fastcsv.reader.CsvRecordHandler, de.siegmar.fastcsv.reader.NamedCsvRecordHandler, de.siegmar.fastcsv.reader.StringArrayHandler
Type Parameters
<T>
the type of the resulting records
Imports
java.util.Objects, de.siegmar.fastcsv.util.Preconditions

Abstract base class for CsvCallbackHandler implementations.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class

Field Summary

Modifier and TypeField and Description
private static final int
protected int
fieldIdx

The current index in the internal fields array.

protected final FieldModifier
fieldModifier

The field modifier.

protected String[]
fields

The internal fields array.

protected final int
maxFields

The maximum number of fields a single record may have.

protected final int
maxFieldSize

The maximum number of characters a single field may have.

protected final int
maxRecordSize

The maximum number of characters a single record may have.

protected int
recordSize

The total size (sum of all characters) of the current record.

protected RecordType
recordType

The type of the current record.

protected long
startingLineNumber

The starting line number of the current record.

Constructor Summary

AccessConstructor and Description
protected
AbstractInternalCsvCallbackHandler(final int
the maximum number of fields; must be > 0
maxFields
,
final int
the maximum field size; must be > 0
maxFieldSize
,
final int
the maximum record size; must be > 0 and >= maxFieldSize
maxRecordSize
,
final FieldModifier
the field modifier; must not be null
fieldModifier
)

Constructs a new instance with the given configuration.

Method Summary

Modifier and TypeMethod and Description
protected 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 void
beginRecord(final long startingLineNumber)

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

Called at the beginning of each record.

protected String[]

Returns:

the compact fields array
compactFields
()

Builds a compact fields array (a copy of the internal fields array with the length of the current record).

private void
protected int
getFieldCount()

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

Returns the number of fields in the record.

public RecordType
getRecordType()

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

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

private String
private String
protected String

Returns:

the modified comment value
modifyComment
(final String
the comment value
field
)

Modifies comment value.

protected String

Returns:

the modified field value
modifyField
(final String
the field value
value
,
final boolean
true if the field was quoted
quoted
)

Modifies field value.

protected 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 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

DEFAULT_INITIAL_FIELDS_SIZEback to summary
private static final int DEFAULT_INITIAL_FIELDS_SIZE
fieldIdxback to summary
protected int fieldIdx

The current index in the internal fields array.

fieldModifierback to summary
protected final FieldModifier fieldModifier

The field modifier.

fieldsback to summary
protected String[] fields

The internal fields array.

maxFieldsback to summary
protected final int maxFields

The maximum number of fields a single record may have.

maxFieldSizeback to summary
protected final int maxFieldSize

The maximum number of characters a single field may have.

maxRecordSizeback to summary
protected final int maxRecordSize

The maximum number of characters a single record may have.

recordSizeback to summary
protected int recordSize

The total size (sum of all characters) of the current record.

recordTypeback to summary
protected RecordType recordType

The type of the current record.

startingLineNumberback to summary
protected long startingLineNumber

The starting line number of the current record.

See beginRecord(long).

Constructor Detail

AbstractInternalCsvCallbackHandlerback to summary
protected AbstractInternalCsvCallbackHandler(final int maxFields, final int maxFieldSize, final int maxRecordSize, final FieldModifier fieldModifier)

Constructs a new instance with the given configuration.

Parameters
maxFields:int

the maximum number of fields; must be > 0

maxFieldSize:int

the maximum field size; must be > 0

maxRecordSize:int

the maximum record size; must be > 0 and >= maxFieldSize

fieldModifier:FieldModifier

the field modifier; must not be null

Exceptions
IllegalArgumentException:
if the arguments are invalid
NullPointerException:
if null is passed

Method Detail

addFieldback to summary
protected 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. Materializes the field value, apply field modifier, checks constraints and adds the field to the record.

Annotations
@Override
Exceptions
CsvParseException:
if the addition exceeds the limit of record size or maximum fields count.
beginRecordback to summary
protected 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.

Annotations
@SuppressWarnings:checkstyle:HiddenField
@Override
compactFieldsback to summary
protected String[] compactFields()

Builds a compact fields array (a copy of the internal fields array with the length of the current record).

In contrast to the class property fields, the returned array does only contain the fields of the current record.

Returns:String[]

the compact fields array

extendCapacityback to summary
private void extendCapacity()
getFieldCountback to summary
protected int getFieldCount()

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

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

Returns the number of fields in the record.

The CsvReader will verify that the number of fields in each record matches the number of fields in the first record unless de.siegmar.fastcsv.reader.CsvReader.CsvReaderBuilder#allowExtraFields(boolean) or de.siegmar.fastcsv.reader.CsvReader.CsvReaderBuilder#allowMissingFields(boolean) are set to true.

Annotations
@Override
getRecordTypeback to summary
public 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
maxFieldSizeExceededMessageback to summary
private String maxFieldSizeExceededMessage()
maxRecordSizeExceededMessageback to summary
private String maxRecordSizeExceededMessage()
modifyCommentback to summary
protected String modifyComment(final String field)

Modifies comment value.

Parameters
field:String

the comment value

Returns:String

the modified comment value

modifyFieldback to summary
protected String modifyField(final String value, final boolean quoted)

Modifies field value.

Parameters
value:String

the field value

quoted:boolean

true if the field was quoted

Returns:String

the modified field value

setCommentback to summary
protected 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. Materializes the comment value, apply field modifier, checks constraints and adds the field to the record.

Annotations
@Override
Exceptions
CsvParseException:
if the addition exceeds the limit of record size.
setEmptyback to summary
protected void setEmpty()

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

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

Called for each empty line.

Annotations
@Override
de.siegmar.fastcsv.reader back to summary

public abstract Class AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder<T extends AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder<?>>

extends Object
Class Inheritance
  • java.lang.Object
  • de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder
Known Direct Subclasses
de.siegmar.fastcsv.reader.CsvRecordHandler.CsvRecordHandlerBuilder, de.siegmar.fastcsv.reader.NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder, de.siegmar.fastcsv.reader.StringArrayHandler.StringArrayHandlerBuilder
Annotations
@SuppressWarnings:PMD.AvoidFieldNameMatchingMethodName
Type Parameters
<T>
the type of the actual builder

Abstract builder for AbstractInternalCsvCallbackHandler subclasses.

This class is for internal use only and should not be used directly. It will be sealed in a future release.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
protected FieldModifier
fieldModifier

The field modifier.

protected int
maxFields

The maximum number of fields a single record may have.

protected int
maxFieldSize

The maximum number of characters a single field may have.

protected int
maxRecordSize

The maximum number of characters a single record may have.

Constructor Summary

AccessConstructor and Description
protected
AbstractInternalCsvCallbackHandlerBuilder()

Constructs a new default instance.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

This updated object, allowing additional method calls to be chained together.
fieldModifier
(final FieldModifier
the field modifier; must not be null (default: FieldModifiers#NOP)
fieldModifier
)

Sets the field modifier.

public T

Returns:

This updated object, allowing additional method calls to be chained together.
maxFields
(final int
the maximum fields a record may have; must be > 0 (default: 16384)
maxFields
)

Defines the maximum number of fields a single record may have.

public T

Returns:

This updated object, allowing additional method calls to be chained together.
maxFieldSize
(final int
the maximum field size; must be > 0 (default: 16777216)
maxFieldSize
)

Defines the maximum number of characters a single field may have.

public T

Returns:

This updated object, allowing additional method calls to be chained together.
maxRecordSize
(final int
the maximum record size; must be > 0 (default: 67108864)
maxRecordSize
)

Defines the maximum number of characters a single record may have.

protected abstract T

Returns:

This object of subclass type.
self
()

Method to be implemented by subclasses to return the correct type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MAX_FIELD_SIZEback to summary
private static final int DEFAULT_MAX_FIELD_SIZE
DEFAULT_MAX_FIELDSback to summary
private static final int DEFAULT_MAX_FIELDS
DEFAULT_MAX_RECORD_SIZEback to summary
private static final int DEFAULT_MAX_RECORD_SIZE
fieldModifierback to summary
protected FieldModifier fieldModifier

The field modifier. The default value is FieldModifiers#NOP.

maxFieldsback to summary
protected int maxFields

The maximum number of fields a single record may have. The default value is 16384.

maxFieldSizeback to summary
protected int maxFieldSize

The maximum number of characters a single field may have. The default value is 16777216.

maxRecordSizeback to summary
protected int maxRecordSize

The maximum number of characters a single record may have. The default value is 67108864.

Constructor Detail

AbstractInternalCsvCallbackHandlerBuilderback to summary
protected AbstractInternalCsvCallbackHandlerBuilder()

Constructs a new default instance.

Method Detail

fieldModifierback to summary
public T fieldModifier(final FieldModifier fieldModifier)

Sets the field modifier.

Parameters
fieldModifier:FieldModifier

the field modifier; must not be null (default: FieldModifiers#NOP)

Returns:T

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
NullPointerException:
if null is passed
maxFieldsback to summary
public T maxFields(final int maxFields)

Defines the maximum number of fields a single record may have.

This constraint is enforced for all fields, including the header.

Parameters
maxFields:int

the maximum fields a record may have; must be > 0 (default: 16384)

Returns:T

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
IllegalArgumentException:
if the argument is less than 1
maxFieldSizeback to summary
public T maxFieldSize(final int maxFieldSize)

Defines the maximum number of characters a single field may have.

This constraint is enforced for all fields, including the header and comments. The size of the field is determined after field modifiers are applied.

In contrast to de.siegmar.fastcsv.reader.CsvReader.CsvReaderBuilder#maxBufferSize(int) which enforces the maximum field size before the field modifier is applied, this constraint allows more precise control over the field size as field modifiers may have a significant impact on the field size.

Parameters
maxFieldSize:int

the maximum field size; must be > 0 (default: 16777216)

Returns:T

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
IllegalArgumentException:
if the argument is less than 1
See Also
de.siegmar.fastcsv.reader.CsvReader.CsvReaderBuilder#maxBufferSize(int)
maxRecordSizeback to summary
public T maxRecordSize(final int maxRecordSize)

Defines the maximum number of characters a single record may have.

This constraint is enforced for all fields, including the header and comments. The size of the record is the sum of the sizes of all fields. The size of each field is determined after field modifiers are applied.

Make sure that maxRecordSize is >= maxFieldSize.

Parameters
maxRecordSize:int

the maximum record size; must be > 0 (default: 67108864)

Returns:T

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
IllegalArgumentException:
if the argument is less than 1
See Also
maxFieldSize(int)
selfback to summary
protected abstract T self()

Method to be implemented by subclasses to return the correct type.

Returns:T

This object of subclass type.