Class MultiResourceItemWriter<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemWriter<T>
- org.springframework.batch.item.file.MultiResourceItemWriter<T>
- Type Parameters:
T- item type
- All Implemented Interfaces:
ItemStream,ItemStreamWriter<T>,ItemWriter<T>
public class MultiResourceItemWriter<T> extends AbstractItemStreamItemWriter<T>
Wraps aResourceAwareItemWriterItemStreamand creates a new output resource when the count of items written in current resource exceedssetItemCountLimitPerResource(int). Suffix creation can be customized withsetResourceSuffixCreator(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 bysetItemCountLimitPerResource(int)and (limit + chunk size).- Author:
- Robert Kasanicky
Constructor Summary
Constructors Constructor Description MultiResourceItemWriter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()No-op.voidopen(ExecutionContext executionContext)No-op.voidsetDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)Delegate used for actual writing of the output.voidsetItemCountLimitPerResource(int itemCountLimitPerResource)After this limit is exceeded the next chunk will be written into newly created resource.voidsetResource(org.springframework.core.io.Resource resource)Prototype for output resources.voidsetResourceSuffixCreator(ResourceSuffixCreator suffixCreator)Allows customization of the suffix of the created resources based on the index.voidsetSaveState(boolean saveState)Indicates that the state of the reader will be saved after each commit.voidupdate(ExecutionContext executionContext)Return emptyExecutionContext.voidwrite(java.util.List<? extends T> items)Process the supplied data element.Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
Method Detail
write
public void write(java.util.List<? extends T> items) throws java.lang.Exception
Description copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation.- Parameters:
items- items to be written- Throws:
java.lang.Exception- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
setResourceSuffixCreator
public void setResourceSuffixCreator(ResourceSuffixCreator suffixCreator)
Allows customization of the suffix of the created resources based on the index.- Parameters:
suffixCreator-ResourceSuffixCreatorto be used by the writer.
setItemCountLimitPerResource
public void setItemCountLimitPerResource(int itemCountLimitPerResource)
After this limit is exceeded the next chunk will be written into newly created resource.- Parameters:
itemCountLimitPerResource- int item threshold used to determine when a new resource should be created.
setDelegate
public void setDelegate(ResourceAwareItemWriterItemStream<? super T> delegate)
Delegate used for actual writing of the output.- Parameters:
delegate-ResourceAwareItemWriterItemStreamthat will be used to write the output.
setResource
public void setResource(org.springframework.core.io.Resource resource)
Prototype for output resources. Actual output files will be created in the same directory and use the same name as this prototype with appended suffix (according tosetResourceSuffixCreator(ResourceSuffixCreator).- Parameters:
resource- The prototype resource.
setSaveState
public void setSaveState(boolean saveState)
Indicates that the state of the reader will be saved after each commit.- Parameters:
saveState- true the state is saved.
close
public void close() throws ItemStreamExceptionDescription copied from class:ItemStreamSupportNo-op.- Specified by:
closein interfaceItemStream- Overrides:
closein classItemStreamSupport- Throws:
ItemStreamException- See Also:
ItemStream.close()
open
public void open(ExecutionContext executionContext) throws ItemStreamException
Description copied from class:ItemStreamSupportNo-op.- Specified by:
openin interfaceItemStream- Overrides:
openin classItemStreamSupport- Parameters:
executionContext- current step'sExecutionContext. Will be the executionContext from the last run of the step on a restart.- Throws:
ItemStreamException- See Also:
ItemStream.open(ExecutionContext)
update
public void update(ExecutionContext executionContext) throws ItemStreamException
Description copied from class:ItemStreamSupportReturn emptyExecutionContext.- Specified by:
updatein interfaceItemStream- Overrides:
updatein classItemStreamSupport- Parameters:
executionContext- to be updated- Throws:
ItemStreamException- See Also:
ItemStream.update(ExecutionContext)