Class FlatFileItemReaderBuilder<T>
java.lang.Object
org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder<T>
A builder implementation for the
FlatFileItemReader.- Since:
- 4.0
- Author:
- Michael Minella, Glenn Renfro, Mahmoud Ben Hassine, Drummond Dawson
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for constructing aDelimitedLineTokenizerstatic classA builder for constructing aFixedLengthTokenizer -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddComment(String comment) Add a string to the list of Strings that indicate commented lines.beanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Configures theBeanFactoryused to create the beans that are returned as items.beanMapperStrict(boolean beanMapperStrict) If set to true, mapping will fail if theFieldSetcontains fields that cannot be mapped to the bean.Configure a customBufferedReaderFactoryfor the reader.build()Builds theFlatFileItemReader.Set an array of Strings that indicate lines that are comments (and therefore skipped by the reader).currentItemCount(int currentItemCount) Index for the current item.customEditors(Map<Class<?>, PropertyEditor> customEditors) Register custom type converters for beans being mapped.Returns an instance of aFlatFileItemReaderBuilder.DelimitedBuilderfor building aDelimitedLineTokenizer.distanceLimit(int distanceLimit) Configures the maximum tolerance between the actual spelling of a field's name and the property's name.Configure the encoding used by the reader to read the input source.fieldSetMapper(FieldSetMapper<T> mapper) AFieldSetMapperimplementation to be used.Returns an instance of aFlatFileItemReaderBuilder.FixedLengthBuilderfor building aFixedLengthTokenizer.lineMapper(LineMapper<T> lineMapper) ALineMapperimplementation to be used.linesToSkip(int linesToSkip) The number of lines to skip at the beginning of reading the file.lineTokenizer(LineTokenizer tokenizer) ALineTokenizerimplementation to be used.maxItemCount(int maxItemCount) Configure the max number of items to be read.The name used to calculate the key within theExecutionContext.prototypeBeanName(String prototypeBeanName) Configures the id of a prototype scoped bean to be used as the item returned by the reader.Configure a customRecordSeparatorPolicyfor the reader.resource(org.springframework.core.io.Resource resource) TheResourceto be used as input.saveState(boolean saveState) Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.skippedLinesCallback(LineCallbackHandler callback) A callback to be called for each line that is skipped.strict(boolean strict) Configure if the reader should be in strict mode (require the inputResourceto exist).targetType(Class<T> targetType) The class that will represent the "item" to be returned from the reader.
-
Field Details
-
logger
protected org.apache.commons.logging.Log logger
-
-
Constructor Details
-
FlatFileItemReaderBuilder
public FlatFileItemReaderBuilder()
-
-
Method Details
-
saveState
Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.- Parameters:
saveState- defaults to true- Returns:
- The current instance of the builder.
-
name
The name used to calculate the key within theExecutionContext. Required ifsaveState(boolean)is set to true.- Parameters:
name- name of the reader instance- Returns:
- The current instance of the builder.
- See Also:
-
maxItemCount
Configure the max number of items to be read.- Parameters:
maxItemCount- the max items to be read- Returns:
- The current instance of the builder.
- See Also:
-
currentItemCount
Index for the current item. Used on restarts to indicate where to start from.- Parameters:
currentItemCount- current index- Returns:
- this instance for method chaining
- See Also:
-
addComment
Add a string to the list of Strings that indicate commented lines. Defaults toFlatFileItemReader.DEFAULT_COMMENT_PREFIXES.- Parameters:
comment- the string to define a commented line.- Returns:
- The current instance of the builder.
- See Also:
-
comments
Set an array of Strings that indicate lines that are comments (and therefore skipped by the reader). This method overrides the default comment prefixes which areFlatFileItemReader.DEFAULT_COMMENT_PREFIXES.- Parameters:
comments- an array of strings to identify comments.- Returns:
- The current instance of the builder.
- See Also:
-
recordSeparatorPolicy
Configure a customRecordSeparatorPolicyfor the reader.- Parameters:
policy- custom policy- Returns:
- The current instance of the builder.
- See Also:
-
bufferedReaderFactory
Configure a customBufferedReaderFactoryfor the reader.- Parameters:
factory- custom factory- Returns:
- The current instance of the builder.
- See Also:
-
resource
TheResourceto be used as input.- Parameters:
resource- the input to the reader.- Returns:
- The current instance of the builder.
- See Also:
-
strict
Configure if the reader should be in strict mode (require the inputResourceto exist).- Parameters:
strict- true if the input file is required to exist.- Returns:
- The current instance of the builder.
- See Also:
-
encoding
Configure the encoding used by the reader to read the input source. Default value isFlatFileItemReader.DEFAULT_CHARSET.- Parameters:
encoding- to use to read the input source.- Returns:
- The current instance of the builder.
- See Also:
-
linesToSkip
The number of lines to skip at the beginning of reading the file.- Parameters:
linesToSkip- number of lines to be skipped.- Returns:
- The current instance of the builder.
- See Also:
-
skippedLinesCallback
A callback to be called for each line that is skipped.- Parameters:
callback- the callback- Returns:
- The current instance of the builder.
- See Also:
-
lineMapper
ALineMapperimplementation to be used.- Parameters:
lineMapper-LineMapper- Returns:
- The current instance of the builder.
- See Also:
-
fieldSetMapper
AFieldSetMapperimplementation to be used.- Parameters:
mapper- aFieldSetMapper- Returns:
- The current instance of the builder.
- See Also:
-
lineTokenizer
ALineTokenizerimplementation to be used.- Parameters:
tokenizer- aLineTokenizer- Returns:
- The current instance of the builder.
- See Also:
-
delimited
Returns an instance of aFlatFileItemReaderBuilder.DelimitedBuilderfor building aDelimitedLineTokenizer. TheDelimitedLineTokenizerconfigured by this builder will only be used if one is not explicitly configured vialineTokenizer- Returns:
- a
FlatFileItemReaderBuilder.DelimitedBuilder
-
fixedLength
Returns an instance of aFlatFileItemReaderBuilder.FixedLengthBuilderfor building aFixedLengthTokenizer. TheFixedLengthTokenizerconfigured by this builder will only be used if thelineTokenizerhas not been configured.- Returns:
- a
FlatFileItemReaderBuilder.FixedLengthBuilder
-
targetType
The class that will represent the "item" to be returned from the reader. This class is used via theBeanWrapperFieldSetMapper. If more complex logic is required, providing your ownFieldSetMapperviafieldSetMapperis required.- Parameters:
targetType- The class to map to- Returns:
- The current instance of the builder.
- See Also:
-
prototypeBeanName
Configures the id of a prototype scoped bean to be used as the item returned by the reader.- Parameters:
prototypeBeanName- the name of a prototype scoped bean- Returns:
- The current instance of the builder.
- See Also:
-
beanFactory
public FlatFileItemReaderBuilder<T> beanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Configures theBeanFactoryused to create the beans that are returned as items.- Parameters:
beanFactory- aBeanFactory- Returns:
- The current instance of the builder.
- See Also:
-
customEditors
Register custom type converters for beans being mapped.- Parameters:
customEditors- aMapof editors- Returns:
- The current instance of the builder.
- See Also:
-
distanceLimit
Configures the maximum tolerance between the actual spelling of a field's name and the property's name.- Parameters:
distanceLimit- distance limit to set- Returns:
- The current instance of the builder.
- See Also:
-
beanMapperStrict
If set to true, mapping will fail if theFieldSetcontains fields that cannot be mapped to the bean.- Parameters:
beanMapperStrict- defaults to false- Returns:
- The current instance of the builder.
- See Also:
-
build
Builds theFlatFileItemReader.- Returns:
- a
FlatFileItemReader
-