AbstractItemCountingItemStreamItemWriter extends AbstractItemStreamItemWriter<T> { @Override public void write(List<? extends T> items) throws Exception { for (T item : items) { if (item instanceof IndexedItem && useItemIndex) { Long index = ((IndexedItem) item).getIndex(); if (index != null) { jumpToItem(index.intValue()); } } if (currentItemCount < maxItemCount) { if (doWrite(item)) { currentItemCount++; } currentItemIndex++; } LOGGER.trace("[currentItemCount={}, currentItemIndex={}]", currentItemCount, currentItemIndex); } LOGGER.debug("Written {} items", items); }  @Override void write(List<? extends T> items); @Override void close(); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); boolean isSaveState(); void setSaveState(boolean saveState); void setCurrentItemIndex(int itemIndex); void setMaxItemCount(int count); void setUseItemIndex(boolean useItemIndex);  }
@Test public void testWrite() throws Exception { ExecutionContext context = new ExecutionContext(); writer.open(context); writer.write(Arrays.asList( new Indexed("a"), new Indexed("b"), new Indexed("c"), new Indexed("d"), new Indexed("e"), new Indexed("f") )); writer.update(context); Assert.assertEquals("abcde", writer.toString()); }