public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWriter<T> implements ResourceAwareItemWriterItemStream<T>, org.springframework.beans.factory.InitializingBean
Resource
which must
represent a writable file.Modifier and Type | Class and Description |
---|---|
protected class |
AbstractFileItemWriter.OutputState
Encapsulates the runtime state of the writer.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
append |
static java.lang.String |
DEFAULT_CHARSET |
static java.lang.String |
DEFAULT_LINE_SEPARATOR |
static boolean |
DEFAULT_TRANSACTIONAL |
protected java.lang.String |
lineSeparator |
protected static org.apache.commons.logging.Log |
logger |
protected boolean |
shouldDeleteIfExists |
protected AbstractFileItemWriter.OutputState |
state |
Constructor and Description |
---|
AbstractFileItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
close()
No-op.
|
protected abstract java.lang.String |
doWrite(java.util.List<? extends T> items)
Write out a string of items followed by a "new line", where the format of the new
line separator is determined by the underlying operating system.
|
protected AbstractFileItemWriter.OutputState |
getOutputState() |
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 |
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 static final boolean DEFAULT_TRANSACTIONAL
protected static final org.apache.commons.logging.Log logger
public static final java.lang.String DEFAULT_LINE_SEPARATOR
public static final java.lang.String DEFAULT_CHARSET
protected AbstractFileItemWriter.OutputState state
protected boolean shouldDeleteIfExists
protected java.lang.String lineSeparator
protected boolean append
public void setForceSync(boolean forceSync)
forceSync
- the flag value to setpublic void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- the line separator to setpublic void setResource(org.springframework.core.io.Resource resource)
setResource
in interface ResourceAwareItemWriterItemStream<T>
resource
- the resource to be written topublic void setEncoding(java.lang.String newEncoding)
newEncoding
- String
containing the encoding to be used for
the writer.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
- if true, state will be persistedpublic void setHeaderCallback(FlatFileHeaderCallback headerCallback)
headerCallback
- FlatFileHeaderCallback
to generate the headerpublic void setFooterCallback(FlatFileFooterCallback footerCallback)
footerCallback
- FlatFileFooterCallback
to generate the footerpublic void setTransactional(boolean transactional)
transactional
- true if writing to buffer should be delayed.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 an error occurs while writing items to the output streamprotected abstract java.lang.String doWrite(java.util.List<? extends T> items)
items
- to be writtenpublic 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)
protected AbstractFileItemWriter.OutputState getOutputState()