public class FlatFileItemWriter<T> extends ExecutionContextUserSupport 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()
If any resources are needed for the stream to operate they need to be destroyed here.
|
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(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(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)
Indicates that the execution context provided during open is about to be saved.
|
void |
write(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.
|
getKey, getName, setName
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
InitializingBean.afterPropertiesSet()
public void setForceSync(boolean forceSync)
forceSync
- the flag value to setpublic void setLineSeparator(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(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(List<? extends T> items) throws Exception
write
in interface ItemWriter<T>
items
- list of items to be written to output streamException
- if the transformer or file output fail,
WriterNotOpenException if the writer has not been initialized.public void close()
ItemStream
close
in interface ItemStream
ItemStream.close()
public void open(ExecutionContext executionContext) throws ItemStreamException
open
in interface ItemStream
ItemStreamException
ItemStream.open(ExecutionContext)
public void update(ExecutionContext executionContext)
ItemStream
update
in interface ItemStream
executionContext
- to be updatedItemStream.update(ExecutionContext)
Copyright © 2013 SpringSource. All rights reserved.