Class FlatFileItemWriterBuilder<T>
- java.lang.Object
- org.springframework.batch.item.file.builder.FlatFileItemWriterBuilder<T>
public class FlatFileItemWriterBuilder<T> extends java.lang.Object
A builder implementation for theFlatFileItemWriter
- Since:
- 4.0
- Author:
- Michael Minella, Glenn Renfro, Mahmoud Ben Hassine
- See Also:
FlatFileItemWriter
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FlatFileItemWriterBuilder.DelimitedBuilder<T>
A builder for constructing aDelimitedLineAggregator
static class
FlatFileItemWriterBuilder.FormattedBuilder<T>
A builder for constructing aFormatterLineAggregator
.
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Log
logger
Constructor Summary
Constructors Constructor Description FlatFileItemWriterBuilder()
Method Summary
All Methods Instance Methods Concrete Methods 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 aFlatFileItemWriter
.FlatFileItemWriterBuilder.DelimitedBuilder<T>
delimited()
Returns an instance of aFlatFileItemWriterBuilder.DelimitedBuilder
for building aDelimitedLineAggregator
.FlatFileItemWriterBuilder<T>
encoding(java.lang.String encoding)
Encoding used for output.FlatFileItemWriterBuilder<T>
footerCallback(FlatFileFooterCallback callback)
A callback for footer processingFlatFileItemWriterBuilder<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 aFlatFileItemWriterBuilder.FormattedBuilder
for building aFormatterLineAggregator
.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(java.lang.String lineSeparator)
String used to separate lines in output.FlatFileItemWriterBuilder<T>
name(java.lang.String name)
The name used to calculate the key within theExecutionContext
.FlatFileItemWriterBuilder<T>
resource(org.springframework.core.io.Resource resource)
TheResource
to be used as output.FlatFileItemWriterBuilder<T>
saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
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.
Method Detail
saveState
public FlatFileItemWriterBuilder<T> saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.- Parameters:
saveState
- defaults to true- Returns:
- The current instance of the builder.
name
public FlatFileItemWriterBuilder<T> name(java.lang.String 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:
ItemStreamSupport.setName(String)
resource
public FlatFileItemWriterBuilder<T> resource(org.springframework.core.io.Resource resource)
TheResource
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(java.lang.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(java.lang.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 aFlatFileItemWriterBuilder.DelimitedBuilder
for building aDelimitedLineAggregator
. TheDelimitedLineAggregator
configured by this builder will only be used if one is not explicitly configured vialineAggregator
formatted
public FlatFileItemWriterBuilder.FormattedBuilder<T> formatted()
Returns an instance of aFlatFileItemWriterBuilder.FormattedBuilder
for building aFormatterLineAggregator
. TheFormatterLineAggregator
configured by this builder will only be used if one is not explicitly configured vialineAggregator
build
public FlatFileItemWriter<T> build()
Validates and builds aFlatFileItemWriter
.- Returns:
- a
FlatFileItemWriter