T
- item typepublic class MultiResourceItemWriter<T> extends AbstractItemStreamItemWriter<T>
ResourceAwareItemWriterItemStream
and creates a new output
resource when the count of items written in current resource exceeds
setItemCountLimitPerResource(int)
. Suffix creation can be customized
with setResourceSuffixCreator(ResourceSuffixCreator)
.
Note that new resources are created only at chunk boundaries i.e. the number
of items written into one resource is between the limit set by
setItemCountLimitPerResource(int)
and (limit + chunk size).Constructor and Description |
---|
MultiResourceItemWriter() |
Modifier and Type | Method and Description |
---|---|
void |
close()
No-op.
|
void |
open(ExecutionContext executionContext)
No-op.
|
void |
setDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)
Delegate used for actual writing of the output.
|
void |
setItemCountLimitPerResource(int itemCountLimitPerResource)
After this limit is exceeded the next chunk will be written into newly
created resource.
|
void |
setResource(org.springframework.core.io.Resource resource)
Prototype for output resources.
|
void |
setResourceSuffixCreator(ResourceSuffixCreator suffixCreator)
Allows customization of the suffix of the created resources based on the
index.
|
void |
setSaveState(boolean saveState)
Indicates that the state of the reader will be saved after each commit.
|
void |
update(ExecutionContext executionContext)
Return empty
ExecutionContext . |
void |
write(java.util.List<? extends T> items)
Process the supplied data element.
|
getExecutionContextKey, setExecutionContextName, setName
public void write(java.util.List<? extends T> items) throws java.lang.Exception
ItemWriter
items
- items to be writtenjava.lang.Exception
- if there are errors. The framework will catch the
exception and convert or rethrow it as appropriate.public void setResourceSuffixCreator(ResourceSuffixCreator suffixCreator)
suffixCreator
- ResourceSuffixCreator
to be used by the writer.public void setItemCountLimitPerResource(int itemCountLimitPerResource)
itemCountLimitPerResource
- int item threshold used to determine when a new
resource should be created.public void setDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)
delegate
- ResourceAwareItemWriterItemStream
that will be used
to write the output.public void setResource(org.springframework.core.io.Resource resource)
setResourceSuffixCreator(ResourceSuffixCreator)
.resource
- The prototype resource.public void setSaveState(boolean saveState)
saveState
- true the state is saved.public void close() throws ItemStreamException
ItemStreamSupport
close
in interface ItemStream
close
in class ItemStreamSupport
ItemStreamException
ItemStream.close()
public void open(ExecutionContext executionContext) throws ItemStreamException
ItemStreamSupport
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) throws ItemStreamException
ItemStreamSupport
ExecutionContext
.update
in interface ItemStream
update
in class ItemStreamSupport
executionContext
- to be updatedItemStreamException
ItemStream.update(ExecutionContext)