Class NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder
- Enclosing class:
NamedCsvRecordHandler
NamedCsvRecordHandler.-
Field Summary
Fields inherited from class AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder
fieldModifier, maxFields, maxFieldSize, maxRecordSize -
Method Summary
Modifier and TypeMethodDescriptionallowDuplicateHeaderFields(boolean allowDuplicateHeaderFields) Sets whether duplicate header fields are allowed.build()Builds theNamedCsvRecordHandlerinstance.Sets a predefined header.Sets the header.headerValidator(HeaderValidator headerValidator) Sets a validator that is called once the header is determined – either from the first record (that is not a comment or an empty line) or from a predefined header (seeheader(String...)).returnHeader(boolean returnHeader) Sets whether the header itself should be returned as the first record.self()Method to be implemented by subclasses to return the correct type.Methods inherited from class AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder
fieldModifier, maxFields, maxFieldSize, maxRecordSize
-
Method Details
-
allowDuplicateHeaderFields
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder allowDuplicateHeaderFields(boolean allowDuplicateHeaderFields) Sets whether duplicate header fields are allowed.
When set to
false, aCsvParseExceptionis thrown if the header contains duplicate fields. When set totrue, duplicate fields are allowed. SeeNamedCsvRecordfor details on how duplicate headers are handled.- Parameters:
allowDuplicateHeaderFields- whether duplicate header fields are allowed (default:false)- Returns:
- This updated object, allowing additional method calls to be chained together.
-
header
Sets a predefined header.
When not set, the header is taken from the first record (that is not a comment or an empty line).
- Parameters:
header- the header, must not benull- Returns:
- This updated object, allowing additional method calls to be chained together.
- Throws:
NullPointerException- ifnullis passed- See Also:
-
header
Sets the header.
When not set, the header is taken from the first record (that is not a comment or an empty line).
- Parameters:
header- the header, must not benull- Returns:
- This updated object, allowing additional method calls to be chained together.
- Throws:
NullPointerException- ifnullis passed- See Also:
-
headerValidator
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder headerValidator(HeaderValidator headerValidator) Sets a validator that is called once the header is determined – either from the first record (that is not a comment or an empty line) or from a predefined header (see
header(String...)). Input without any header (e.g., an empty file) yields no records and is not validated.The validator must throw an exception (any
RuntimeException) if the header is not acceptable. While reading, aCsvParseException(as thrown by the standard validators) propagates as-is; any other exception gets wrapped in one. For a predefined header, the validator is already called bybuild()and any exception propagates as-is.The validator is called after the built-in checks (
nullelements, duplicates) have passed.- Parameters:
headerValidator- the validator, must not benull- Returns:
- This updated object, allowing additional method calls to be chained together.
- Throws:
NullPointerException- ifnullis passed- See Also:
-
returnHeader
Sets whether the header itself should be returned as the first record.
When enabled, the first record returned will be a
NamedCsvRecordwith the header fields as its fields and as the header.- Parameters:
returnHeader- whether the header should be returned as the first record (default:false)- Returns:
- This updated object, allowing additional method calls to be chained together.
-
self
Description copied from class:AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilderMethod to be implemented by subclasses to return the correct type.- Specified by:
selfin classAbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder<NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder>- Returns:
- This object of subclass type.
-
build
Builds theNamedCsvRecordHandlerinstance.- Returns:
- the new instance
- Throws:
IllegalArgumentException- if argument constraints are violated (seeAbstractInternalCsvCallbackHandler)CsvParseException- if a predefined header (seeheader(String...)) contains duplicate fields (seeallowDuplicateHeaderFields(boolean)) or is rejected by a configured validator (seeheaderValidator(HeaderValidator))
-