public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> implements ResourceAwareItemWriterItemStream<T>, org.springframework.beans.factory.InitializingBean
Resource
and must represent a writable file.Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
FlatFileItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Assert that mandatory properties (lineAggregator) are set.
|
void |
close()
No-op.
|
void |
open(ExecutionContext executionContext)
Initialize the reader.
|
void |
setAppendAllowed(boolean append)
Flag to indicate that the target file should be appended if it already
exists.
|
void |
setEncoding(java.lang.String newEncoding)
Sets encoding for output template.
|
void |
setFooterCallback(FlatFileFooterCallback footerCallback)
footerCallback will be called after writing the last item to file, but
before the file is closed.
|
void |
setForceSync(boolean forceSync)
Flag to indicate that changes should be force-synced to disk on flush.
|
void |
setHeaderCallback(FlatFileHeaderCallback headerCallback)
headerCallback will be called before writing the first item to file.
|
void |
setLineAggregator(LineAggregator<T> lineAggregator)
Public setter for the
LineAggregator . |
void |
setLineSeparator(java.lang.String lineSeparator)
Public setter for the line separator.
|
void |
setResource(org.springframework.core.io.Resource resource)
Setter for resource.
|
void |
setSaveState(boolean saveState)
Set the flag indicating whether or not state should be saved in the
provided
ExecutionContext during the ItemStream call to
update. |
void |
setShouldDeleteIfEmpty(boolean shouldDeleteIfEmpty)
Flag to indicate that the target file should be deleted if no lines have
been written (other than header and footer) on close.
|
void |
setShouldDeleteIfExists(boolean shouldDeleteIfExists)
Flag to indicate that the target file should be deleted if it already
exists, otherwise it will be created.
|
void |
setTransactional(boolean transactional)
Flag to indicate that writing to the buffer should be delayed if a
transaction is active.
|
void |
update(ExecutionContext executionContext)
Return empty
ExecutionContext . |
void |
write(java.util.List<? extends T> items)
Writes out a string followed by a "new line", where the format of the new
line separator is determined by the underlying operating system.
|
getExecutionContextKey, setExecutionContextName, setName
public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
InitializingBean.afterPropertiesSet()
public void setForceSync(boolean forceSync)
forceSync
- the flag value to setpublic void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- the line separator to setpublic void setLineAggregator(LineAggregator<T> lineAggregator)
LineAggregator
. This will be used to
translate the item into a line for output.lineAggregator
- the LineAggregator
to setpublic void setResource(org.springframework.core.io.Resource resource)
setResource
in interface ResourceAwareItemWriterItemStream<T>
resource
- public void setEncoding(java.lang.String newEncoding)
public void setShouldDeleteIfExists(boolean shouldDeleteIfExists)
appendAllowed
is also false then there will be an exception when the
stream is opened to prevent existing data being potentially corrupted.shouldDeleteIfExists
- the flag value to setpublic void setAppendAllowed(boolean append)
shouldDeleteIfExists
is
automatically set to false, so that flag should not be set explicitly.
Defaults value is false.append
- the flag value to setpublic void setShouldDeleteIfEmpty(boolean shouldDeleteIfEmpty)
shouldDeleteIfEmpty
- the flag value to setpublic void setSaveState(boolean saveState)
ExecutionContext
during the ItemStream
call to
update. Setting this to false means that it will always start at the
beginning on a restart.saveState
- public void setHeaderCallback(FlatFileHeaderCallback headerCallback)
public void setFooterCallback(FlatFileFooterCallback footerCallback)
public void setTransactional(boolean transactional)
public void write(java.util.List<? extends T> items) throws java.lang.Exception
write
in interface ItemWriter<T>
items
- list of items to be written to output streamjava.lang.Exception
- if the transformer or file output fail,
WriterNotOpenException if the writer has not been initialized.public void close()
ItemStreamSupport
close
in interface ItemStream
close
in class ItemStreamSupport
ItemStream.close()
public void open(ExecutionContext executionContext) throws ItemStreamException
open
in interface ItemStream
open
in class ItemStreamSupport
executionContext
- current step's ExecutionContext
. Will be the
executionContext from the last run of the step on a restart.ItemStreamException
ItemStream.open(ExecutionContext)
public void update(ExecutionContext executionContext)
ItemStreamSupport
ExecutionContext
.update
in interface ItemStream
update
in class ItemStreamSupport
executionContext
- to be updatedItemStream.update(ExecutionContext)