org.springframework.batch.item.file.builder

## Class FlatFileItemReaderBuilder<T>

- java.lang.Object
- - org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder<T>

-     public class FlatFileItemReaderBuilder<T>
      extends java.lang.Object

  A builder implementation for the `FlatFileItemReader`.
  Since:
    4.0
  Author:
    Michael Minella, Glenn Renfro, Mahmoud Ben Hassine, Drummond Dawson
  See Also:
    `FlatFileItemReader`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FlatFileItemReaderBuilder.DelimitedBuilder<T>` A builder for constructing a `DelimitedLineTokenizer`
    `static class` | `FlatFileItemReaderBuilder.FixedLengthBuilder<T>` A builder for constructing a `FixedLengthTokenizer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.apache.commons.logging.Log` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FlatFileItemReaderBuilder()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `FlatFileItemReaderBuilder<T>` | `addComment(java.lang.String comment)` Add a string to the list of Strings that indicate commented lines.
    `FlatFileItemReaderBuilder<T>` | `beanFactory(org.springframework.beans.factory.BeanFactory beanFactory)` Configures the `BeanFactory` used to create the beans that are returned as items.
    `FlatFileItemReaderBuilder<T>` | `beanMapperStrict(boolean beanMapperStrict)` If set to true, mapping will fail if the `FieldSet` contains fields that cannot be mapped to the bean.
    `FlatFileItemReaderBuilder<T>` | `bufferedReaderFactory(BufferedReaderFactory factory)` Configure a custom `BufferedReaderFactory` for the reader.
    `FlatFileItemReader<T>` | `build()` Builds the `FlatFileItemReader`.
    `FlatFileItemReaderBuilder<T>` | `comments(java.lang.String... comments)` Set an array of Strings that indicate lines that are comments (and therefore skipped by the reader).
    `FlatFileItemReaderBuilder<T>` | `currentItemCount(int currentItemCount)` Index for the current item.
    `FlatFileItemReaderBuilder<T>` | `customEditors(java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> customEditors)` Register custom type converters for beans being mapped.
    `FlatFileItemReaderBuilder.DelimitedBuilder<T>` | `delimited()` Returns an instance of a `FlatFileItemReaderBuilder.DelimitedBuilder` for building a `DelimitedLineTokenizer`.
    `FlatFileItemReaderBuilder<T>` | `distanceLimit(int distanceLimit)` Configures the maximum tolerance between the actual spelling of a field's name and the property's name.
    `FlatFileItemReaderBuilder<T>` | `encoding(java.lang.String encoding)` Configure the encoding used by the reader to read the input source.
    `FlatFileItemReaderBuilder<T>` | `fieldSetMapper(FieldSetMapper<T> mapper)` A `FieldSetMapper` implementation to be used.
    `FlatFileItemReaderBuilder.FixedLengthBuilder<T>` | `fixedLength()` Returns an instance of a `FlatFileItemReaderBuilder.FixedLengthBuilder` for building a `FixedLengthTokenizer`.
    `FlatFileItemReaderBuilder<T>` | `lineMapper(LineMapper<T> lineMapper)` A `LineMapper` implementation to be used.
    `FlatFileItemReaderBuilder<T>` | `linesToSkip(int linesToSkip)` The number of lines to skip at the beginning of reading the file.
    `FlatFileItemReaderBuilder<T>` | `lineTokenizer(LineTokenizer tokenizer)` A `LineTokenizer` implementation to be used.
    `FlatFileItemReaderBuilder<T>` | `maxItemCount(int maxItemCount)` Configure the max number of items to be read.
    `FlatFileItemReaderBuilder<T>` | `name(java.lang.String name)` The name used to calculate the key within the `ExecutionContext`.
    `FlatFileItemReaderBuilder<T>` | `prototypeBeanName(java.lang.String prototypeBeanName)` Configures the id of a prototype scoped bean to be used as the item returned by the reader.
    `FlatFileItemReaderBuilder<T>` | `recordSeparatorPolicy(RecordSeparatorPolicy policy)` Configure a custom `RecordSeparatorPolicy` for the reader.
    `FlatFileItemReaderBuilder<T>` | `resource(org.springframework.core.io.Resource resource)` The `Resource` to be used as input.
    `FlatFileItemReaderBuilder<T>` | `saveState(boolean saveState)` Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    `FlatFileItemReaderBuilder<T>` | `skippedLinesCallback(LineCallbackHandler callback)` A callback to be called for each line that is skipped.
    `FlatFileItemReaderBuilder<T>` | `strict(boolean strict)` Configure if the reader should be in strict mode (require the input `Resource` to exist).
    `FlatFileItemReaderBuilder<T>` | `targetType(java.lang.Class<? extends T> targetType)` The class that will represent the "item" to be returned from the reader.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### logger

          protected org.apache.commons.logging.Log logger

  - ### Constructor Detail

    - #### FlatFileItemReaderBuilder

          public FlatFileItemReaderBuilder()

  - ### Method Detail

    - #### saveState

          public FlatFileItemReaderBuilder<T> saveState(boolean saveState)

      Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
      Parameters:
        `saveState` - defaults to true
      Returns:
        The current instance of the builder.

    - #### name

          public FlatFileItemReaderBuilder<T> name(java.lang.String name)

      The name used to calculate the key within the `ExecutionContext`. Required if `saveState(boolean)` is set to true.
      Parameters:
        `name` - name of the reader instance
      Returns:
        The current instance of the builder.
      See Also:
        `ItemStreamSupport.setName(String)`

    - #### maxItemCount

          public FlatFileItemReaderBuilder<T> maxItemCount(int 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:
        `AbstractItemCountingItemStreamItemReader.setMaxItemCount(int)`

    - #### currentItemCount

          public FlatFileItemReaderBuilder<T> currentItemCount(int 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:
        `AbstractItemCountingItemStreamItemReader.setCurrentItemCount(int)`

    - #### addComment

          public FlatFileItemReaderBuilder<T> addComment(java.lang.String comment)

      Add a string to the list of Strings that indicate commented lines. Defaults to `FlatFileItemReader.DEFAULT_COMMENT_PREFIXES`.
      Parameters:
        `comment` - the string to define a commented line.
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setComments(String[])`

    - #### comments

          public FlatFileItemReaderBuilder<T> comments(java.lang.String... 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 are `FlatFileItemReader.DEFAULT_COMMENT_PREFIXES`.
      Parameters:
        `comments` - an array of strings to identify comments.
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setComments(String[])`

    - #### recordSeparatorPolicy

          public FlatFileItemReaderBuilder<T> recordSeparatorPolicy(RecordSeparatorPolicy policy)

      Configure a custom `RecordSeparatorPolicy` for the reader.
      Parameters:
        `policy` - custom policy
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setRecordSeparatorPolicy(RecordSeparatorPolicy)`

    - #### bufferedReaderFactory

          public FlatFileItemReaderBuilder<T> bufferedReaderFactory(BufferedReaderFactory factory)

      Configure a custom `BufferedReaderFactory` for the reader.
      Parameters:
        `factory` - custom factory
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setBufferedReaderFactory(BufferedReaderFactory)`

    - #### resource

          public FlatFileItemReaderBuilder<T> resource(org.springframework.core.io.Resource resource)

      The `Resource` to be used as input.
      Parameters:
        `resource` - the input to the reader.
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setResource(Resource)`

    - #### strict

          public FlatFileItemReaderBuilder<T> strict(boolean strict)

      Configure if the reader should be in strict mode (require the input `Resource` to exist).
      Parameters:
        `strict` - true if the input file is required to exist.
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setStrict(boolean)`

    - #### encoding

          public FlatFileItemReaderBuilder<T> encoding(java.lang.String encoding)

      Configure the encoding used by the reader to read the input source. Default value is `FlatFileItemReader.DEFAULT_CHARSET`.
      Parameters:
        `encoding` - to use to read the input source.
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setEncoding(String)`

    - #### linesToSkip

          public FlatFileItemReaderBuilder<T> linesToSkip(int 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:
        `FlatFileItemReader.setLinesToSkip(int)`

    - #### skippedLinesCallback

          public FlatFileItemReaderBuilder<T> skippedLinesCallback(LineCallbackHandler callback)

      A callback to be called for each line that is skipped.
      Parameters:
        `callback` - the callback
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setSkippedLinesCallback(LineCallbackHandler)`

    - #### lineMapper

          public FlatFileItemReaderBuilder<T> lineMapper(LineMapper<T> lineMapper)

      A `LineMapper` implementation to be used.
      Parameters:
        `lineMapper` - `LineMapper`
      Returns:
        The current instance of the builder.
      See Also:
        `FlatFileItemReader.setLineMapper(LineMapper)`

    - #### fieldSetMapper

          public FlatFileItemReaderBuilder<T> fieldSetMapper(FieldSetMapper<T> mapper)

      A `FieldSetMapper` implementation to be used.
      Parameters:
        `mapper` - a `FieldSetMapper`
      Returns:
        The current instance of the builder.
      See Also:
        `DefaultLineMapper.setFieldSetMapper(FieldSetMapper)`

    - #### lineTokenizer

          public FlatFileItemReaderBuilder<T> lineTokenizer(LineTokenizer tokenizer)

      A `LineTokenizer` implementation to be used.
      Parameters:
        `tokenizer` - a `LineTokenizer`
      Returns:
        The current instance of the builder.
      See Also:
        `DefaultLineMapper.setLineTokenizer(LineTokenizer)`

    - #### delimited

          public FlatFileItemReaderBuilder.DelimitedBuilder<T> delimited()

      Returns an instance of a `FlatFileItemReaderBuilder.DelimitedBuilder` for building a `DelimitedLineTokenizer`. The `DelimitedLineTokenizer` configured by this builder will only be used if one is not explicitly configured via `lineTokenizer`
      Returns:
        a `FlatFileItemReaderBuilder.DelimitedBuilder`

    - #### fixedLength

          public FlatFileItemReaderBuilder.FixedLengthBuilder<T> fixedLength()

      Returns an instance of a `FlatFileItemReaderBuilder.FixedLengthBuilder` for building a `FixedLengthTokenizer`. The `FixedLengthTokenizer` configured by this builder will only be used if the `lineTokenizer` has not been configured.
      Returns:
        a `FlatFileItemReaderBuilder.FixedLengthBuilder`

    - #### targetType

          public FlatFileItemReaderBuilder<T> targetType(java.lang.Class<? extends T> targetType)

      The class that will represent the "item" to be returned from the reader. This class is used via the `BeanWrapperFieldSetMapper`. If more complex logic is required, providing your own `FieldSetMapper` via `fieldSetMapper` is required.
      Parameters:
        `targetType` - The class to map to
      Returns:
        The current instance of the builder.
      See Also:
        `BeanWrapperFieldSetMapper.setTargetType(Class)`

    - #### prototypeBeanName

          public FlatFileItemReaderBuilder<T> prototypeBeanName(java.lang.String 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:
        `BeanWrapperFieldSetMapper.setPrototypeBeanName(String)`

    - #### beanFactory

          public FlatFileItemReaderBuilder<T> beanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

      Configures the `BeanFactory` used to create the beans that are returned as items.
      Parameters:
        `beanFactory` - a `BeanFactory`
      Returns:
        The current instance of the builder.
      See Also:
        `BeanWrapperFieldSetMapper.setBeanFactory(BeanFactory)`

    - #### customEditors

          public FlatFileItemReaderBuilder<T> customEditors(java.util.Map<java.lang.Class<?>,java.beans.PropertyEditor> customEditors)

      Register custom type converters for beans being mapped.
      Parameters:
        `customEditors` - a `Map` of editors
      Returns:
        The current instance of the builder.
      See Also:
        `BeanWrapperFieldSetMapper.setCustomEditors(Map)`

    - #### distanceLimit

          public FlatFileItemReaderBuilder<T> distanceLimit(int 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:
        `BeanWrapperFieldSetMapper.setDistanceLimit(int)`

    - #### beanMapperStrict

          public FlatFileItemReaderBuilder<T> beanMapperStrict(boolean beanMapperStrict)

      If set to true, mapping will fail if the `FieldSet` contains fields that cannot be mapped to the bean.
      Parameters:
        `beanMapperStrict` - defaults to false
      Returns:
        The current instance of the builder.
      See Also:
        `BeanWrapperFieldSetMapper.setStrict(boolean)`

    - #### build

          public FlatFileItemReader<T> build()

      Builds the `FlatFileItemReader`.
      Returns:
        a `FlatFileItemReader`