Package org.springframework.batch.item.file.builder

# Class FlatFileItemWriterBuilder<T>

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

public class FlatFileItemWriterBuilder<T> extends Object
A builder implementation for the `FlatFileItemWriter`

Since:
  4.0
Author:
  Michael Minella, Glenn Renfro, Mahmoud Ben Hassine, Drummond Dawson
See Also:
  - `FlatFileItemWriter`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `FlatFileItemWriterBuilder.DelimitedBuilder<T>`
  A builder for constructing a `DelimitedLineAggregator`
  `static class`
  `FlatFileItemWriterBuilder.FormattedBuilder<T>`
  A builder for constructing a `FormatterLineAggregator`.

- ## Field Summary

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FlatFileItemWriterBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `FlatFileItemWriterBuilder<T>`
  `append(boolean append)`
  If set to true and the file exists, the output will be appended to the existing file.
  `FlatFileItemWriter<T>`
  `build()`
  Validates and builds a `FlatFileItemWriter`.
  `FlatFileItemWriterBuilder.DelimitedBuilder<T>`
  `delimited()`
  Returns an instance of a `FlatFileItemWriterBuilder.DelimitedBuilder` for building a `DelimitedLineAggregator`.
  `FlatFileItemWriterBuilder<T>`
  `encoding(String encoding)`
  Encoding used for output.
  `FlatFileItemWriterBuilder<T>`
  `footerCallback(FlatFileFooterCallback callback)`
  A callback for footer processing
  `FlatFileItemWriterBuilder<T>`
  `forceSync(boolean forceSync)`
  A flag indicating that changes should be force-synced to disk on flush.
  `FlatFileItemWriterBuilder.FormattedBuilder<T>`
  `formatted()`
  Returns an instance of a `FlatFileItemWriterBuilder.FormattedBuilder` for building a `FormatterLineAggregator`.
  `FlatFileItemWriterBuilder<T>`
  `headerCallback(FlatFileHeaderCallback callback)`
  A callback for header processing.
  `FlatFileItemWriterBuilder<T>`
  `lineAggregator(LineAggregator<T> lineAggregator)`
  Line aggregator used to build the String version of each item.
  `FlatFileItemWriterBuilder<T>`
  `lineSeparator(String lineSeparator)`
  String used to separate lines in output.
  `FlatFileItemWriterBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `FlatFileItemWriterBuilder<T>`
  `resource(org.springframework.core.io.Resource resource)`
  The `Resource` to be used as output.
  `FlatFileItemWriterBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
  `FlatFileItemWriterBuilder<T>`
  `shouldDeleteIfEmpty(boolean shouldDelete)`
  If set to true, once the step is complete, if the resource previously provided is empty, it will be deleted.
  `FlatFileItemWriterBuilder<T>`
  `shouldDeleteIfExists(boolean shouldDelete)`
  If set to true, upon the start of the step, if the resource already exists, it will be deleted and recreated.
  `FlatFileItemWriterBuilder<T>`
  `transactional(boolean transactional)`
  If set to true, the flushing of the buffer is delayed while a transaction is active.

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

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

- ## Field Details

  - ### logger

    protected org.apache.commons.logging.Log logger

- ## Constructor Details

  - ### FlatFileItemWriterBuilder

    public FlatFileItemWriterBuilder()

- ## Method Details

  - ### saveState

    public FlatFileItemWriterBuilder<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 FlatFileItemWriterBuilder<T> name(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)`

  - ### resource

    public FlatFileItemWriterBuilder<T> resource(org.springframework.core.io.Resource resource)
    The `Resource` to be used as output.
    Parameters:
      `resource` - the output of the writer.
    Returns:
      The current instance of the builder.
    See Also:
      - `AbstractFileItemWriter.setResource(Resource)`

  - ### forceSync

    public FlatFileItemWriterBuilder<T> forceSync(boolean forceSync)
    A flag indicating that changes should be force-synced to disk on flush. Defaults to false.
    Parameters:
      `forceSync` - value to set the flag to
    Returns:
      The current instance of the builder.
    See Also:
      - `AbstractFileItemWriter.setForceSync(boolean)`

  - ### lineSeparator

    public FlatFileItemWriterBuilder<T> lineSeparator(String lineSeparator)
    String used to separate lines in output. Defaults to the System property line.separator.
    Parameters:
      `lineSeparator` - value to use for a line separator
    Returns:
      The current instance of the builder.
    See Also:
      - `AbstractFileItemWriter.setLineSeparator(String)`

  - ### lineAggregator

    public FlatFileItemWriterBuilder<T> lineAggregator(LineAggregator<T> lineAggregator)
    Line aggregator used to build the String version of each item.
    Parameters:
      `lineAggregator` - `LineAggregator` implementation
    Returns:
      The current instance of the builder.
    See Also:
      - `FlatFileItemWriter.setLineAggregator(LineAggregator)`

  - ### encoding

    public FlatFileItemWriterBuilder<T> encoding(String encoding)
    Encoding used for output.
    Parameters:
      `encoding` - encoding type.
    Returns:
      The current instance of the builder.
    See Also:
      - `AbstractFileItemWriter.setEncoding(String)`

  - ### shouldDeleteIfEmpty

    public FlatFileItemWriterBuilder<T> shouldDeleteIfEmpty(boolean shouldDelete)
    If set to true, once the step is complete, if the resource previously provided is empty, it will be deleted.
    Parameters:
      `shouldDelete` - defaults to false
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setShouldDeleteIfEmpty(boolean)`

  - ### shouldDeleteIfExists

    public FlatFileItemWriterBuilder<T> shouldDeleteIfExists(boolean shouldDelete)
    If set to true, upon the start of the step, if the resource already exists, it will be deleted and recreated.
    Parameters:
      `shouldDelete` - defaults to true
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setShouldDeleteIfExists(boolean)`

  - ### append

    public FlatFileItemWriterBuilder<T> append(boolean append)
    If set to true and the file exists, the output will be appended to the existing file.
    Parameters:
      `append` - defaults to false
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setAppendAllowed(boolean)`

  - ### headerCallback

    public FlatFileItemWriterBuilder<T> headerCallback(FlatFileHeaderCallback callback)
    A callback for header processing.
    Parameters:
      `callback` - `FlatFileHeaderCallback` impl
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setHeaderCallback(FlatFileHeaderCallback)`

  - ### footerCallback

    public FlatFileItemWriterBuilder<T> footerCallback(FlatFileFooterCallback callback)
    A callback for footer processing
    Parameters:
      `callback` - `FlatFileFooterCallback` impl
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setFooterCallback(FlatFileFooterCallback)`

  - ### transactional

    public FlatFileItemWriterBuilder<T> transactional(boolean transactional)
    If set to true, the flushing of the buffer is delayed while a transaction is active.
    Parameters:
      `transactional` - defaults to true
    Returns:
      The current instance of the builder
    See Also:
      - `AbstractFileItemWriter.setTransactional(boolean)`

  - ### delimited

    public FlatFileItemWriterBuilder.DelimitedBuilder<T> delimited()
    Returns an instance of a `FlatFileItemWriterBuilder.DelimitedBuilder` for building a `DelimitedLineAggregator`. The `DelimitedLineAggregator` configured by this builder will only be used if one is not explicitly configured via `lineAggregator`
    Returns:
      a `FlatFileItemWriterBuilder.DelimitedBuilder`

  - ### formatted

    public FlatFileItemWriterBuilder.FormattedBuilder<T> formatted()
    Returns an instance of a `FlatFileItemWriterBuilder.FormattedBuilder` for building a `FormatterLineAggregator`. The `FormatterLineAggregator` configured by this builder will only be used if one is not explicitly configured via `lineAggregator`
    Returns:
      a `FlatFileItemWriterBuilder.FormattedBuilder`

  - ### build

    public FlatFileItemWriter<T> build()
    Validates and builds a `FlatFileItemWriter`.
    Returns:
      a `FlatFileItemWriter`