public class SingleItemPeekableItemReader<T> extends java.lang.Object implements ItemStreamReader<T>, PeekableItemReader<T>
A PeekableItemReader that allows the user to peek one item ahead.
Repeated calls to peek() will return the same item, and this will be
the next item returned from read().
Intentionally not thread-safe: it wouldn't be possible to honour the peek in multiple threads because only one of the threads that peeked would get that item in the next call to read.
| Constructor and Description |
|---|
SingleItemPeekableItemReader() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
If the delegate is an
ItemStream, just pass the call on,
otherwise reset the peek cache. |
void |
open(ExecutionContext executionContext)
If the delegate is an
ItemStream, just pass the call on,
otherwise reset the peek cache. |
T |
peek()
Peek at the next item, ensuring that if the delegate is an
ItemStream the state is stored for the next call to
update(ExecutionContext). |
T |
read()
Get the next item from the delegate (whether or not it has already been
peeked at).
|
void |
setDelegate(ItemReader<T> delegate)
The item reader to use as a delegate.
|
void |
update(ExecutionContext executionContext)
If there is a cached peek, then retrieve the execution context state from
that point.
|
public void setDelegate(ItemReader<T> delegate)
read().delegate - the delegate to set@Nullable public T read() throws java.lang.Exception, UnexpectedInputException, ParseException
read in interface ItemReader<T>null if the data source is
exhaustedParseException - if there is a problem parsing the current record
(but the next one may still be valid)NonTransientResourceException - if there is a fatal exception in
the underlying resource. After throwing this exception implementations
should endeavour to return null from subsequent calls to read.UnexpectedInputException - if there is an uncategorised problem
with the input data. Assume potentially transient, so subsequent calls to
read might succeed.java.lang.Exception - if an there is a non-specific error.ItemReader.read()@Nullable public T peek() throws java.lang.Exception, UnexpectedInputException, ParseException
ItemStream the state is stored for the next call to
update(ExecutionContext).peek in interface PeekableItemReader<T>java.lang.Exception - if there is a problemUnexpectedInputExceptionParseExceptionPeekableItemReader.peek()public void close()
throws ItemStreamException
ItemStream, just pass the call on,
otherwise reset the peek cache.close in interface ItemStreamItemStreamException - if there is a problemItemStream.close()public void open(ExecutionContext executionContext) throws ItemStreamException
ItemStream, just pass the call on,
otherwise reset the peek cache.open in interface ItemStreamexecutionContext - the current contextItemStreamException - if there is a problemItemStream.open(ExecutionContext)public void update(ExecutionContext executionContext) throws ItemStreamException
update in interface ItemStreamexecutionContext - the current contextItemStreamException - if there is a problemItemStream.update(ExecutionContext)