/** * Move to the given item index. Subclasses should override this method if * there is a more efficient way of moving to given index than re-reading * the input using {@link #doRead()}. * * @param itemIndex index of item (0 based) to jump to. * @throws Exception Allows subclasses to throw checked exceptions for interpretation by the framework */ protected void jumpToItem(int itemIndex) throws Exception { for (int i = 0; i < itemIndex; i++) { read(); } }
@Override public void close() throws ItemStreamException { super.close(); currentItemCount = 0; try { doClose(); } catch (Exception e) { throw new ItemStreamException("Error while closing item reader", e); } }
super.open(executionContext); try { doOpen(); if (!isSaveState()) { return; if (executionContext.containsKey(getExecutionContextKey(READ_COUNT_MAX))) { maxItemCount = executionContext.getInt(getExecutionContextKey(READ_COUNT_MAX)); if (executionContext.containsKey(getExecutionContextKey(READ_COUNT))) { itemCount = executionContext.getInt(getExecutionContextKey(READ_COUNT)); jumpToItem(itemCount);
/** * Update the context and clear the session if stateful. * * @param executionContext the current {@link ExecutionContext} * @throws ItemStreamException if there is a problem */ @Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); helper.clear(); }
@Override public T read() throws Exception, UnexpectedInputException, ParseException { if (currentItemCount >= maxItemCount) { return null; } currentItemCount++; T item = doRead(); if(item instanceof ItemCountAware) { ((ItemCountAware) item).setItemCount(currentItemCount); } return item; }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); if (saveState) { Assert.notNull(executionContext, "ExecutionContext must not be null"); executionContext.putInt(getExecutionContextKey(READ_COUNT), currentItemCount); if (maxItemCount < Integer.MAX_VALUE) { executionContext.putInt(getExecutionContextKey(READ_COUNT_MAX), maxItemCount); } } }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); }
/** * Update the context and clear the session if stateful. * * @param executionContext the current {@link ExecutionContext} * @throws ItemStreamException if there is a problem */ @Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); helper.clear(); }
@Override public T read() throws Exception, UnexpectedInputException, ParseException { if (currentItemCount >= maxItemCount) { return null; } currentItemCount++; T item = doRead(); if(item instanceof ItemCountAware) { ((ItemCountAware) item).setItemCount(currentItemCount); } return item; }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { super.update(executionContext); if (saveState) { Assert.notNull(executionContext, "ExecutionContext must not be null"); executionContext.putInt(getExecutionContextKey(READ_COUNT), currentItemCount); if (maxItemCount < Integer.MAX_VALUE) { executionContext.putInt(getExecutionContextKey(READ_COUNT_MAX), maxItemCount); } } }
super.open(executionContext); try { doOpen(); if (!isSaveState()) { return; if (executionContext.containsKey(getExecutionContextKey(READ_COUNT_MAX))) { maxItemCount = executionContext.getInt(getExecutionContextKey(READ_COUNT_MAX)); if (executionContext.containsKey(getExecutionContextKey(READ_COUNT))) { itemCount = executionContext.getInt(getExecutionContextKey(READ_COUNT)); jumpToItem(itemCount);
@Override public T read() throws Exception { T result = null; if (!noInput) { result = super.read(); if (result == null) { noInput = true; } } return result; }
@Override public void close() throws ItemStreamException { super.close(); currentItemCount = 0; try { doClose(); } catch (Exception e) { throw new ItemStreamException("Error while closing item reader", e); } }
/** * Move to the given item index. Subclasses should override this method if * there is a more efficient way of moving to given index than re-reading * the input using {@link #doRead()}. * * @param itemIndex index of item (0 based) to jump to. * @throws Exception Allows subclasses to throw checked exceptions for interpretation by the framework */ protected void jumpToItem(int itemIndex) throws Exception { for (int i = 0; i < itemIndex; i++) { read(); } }