SortedItemStreamWriter extends ItemStreamSupport implements
        ResourceAwareItemStreamWriter<T>,
        ResourceAwareItemWriterItemStream<T>,
        InitializingBean { @Override public void write(List<? extends T> items) throws Exception { initializeStreams(); try { List<T> allItems = replaceItems(readContent(), items); sort(allItems); writeAll(allItems); } catch (Exception e) { rollback(e); } commit(); }  @Override void afterPropertiesSet(); @Override void open(ExecutionContext executionContext); @Override void write(List<? extends T> items); @Override void setResource(Resource resource); void setWriter(ResourceAwareItemWriterItemStream<? super T> writer); void setReader(ResourceAwareItemReaderItemStream<? extends T> reader); void setComparator(Comparator<? super T> comparator); void setUseTemporaryFile(boolean useTemporaryFile);  }
@Test public void testWrite() throws Exception { sortedItemStreamWriter.write(items); assertFile(); assertSequence("abcdefgh"); }
@Test public void testWriteIndexed() throws Exception { items.get(1).setIndex(1L); sortedItemStreamWriter.write(items); assertFile(); assertSequence("acdefgh"); }