ReaderSpliterator implements Spliterator<String> { public static Stream<String> lineStream(BufferedReader in, int batchSize) { return lineStream(in, batchSize, false); } ReaderSpliterator(BufferedReader reader);  ReaderSpliterator(BufferedReader reader, int batchSize); @Override void forEachRemaining(Consumer<? super String> action); @Override boolean tryAdvance(Consumer<? super String> action); @Override Spliterator<String> trySplit(); @Override long estimateSize(); @Override int characteristics(); static Stream<String> lineStream(BufferedReader in, int batchSize); static Stream<String> lineStream(BufferedReader in, int batchSize, boolean isParallel);  }
@Test public void testParallelStreamSmallBatch() throws FileNotFoundException { try( Stream<String> stream = ReaderSpliterator.lineStream(getReader(), 2)) { Map<String, Integer> count = stream.parallel().map( s -> s.trim()) .collect(Collectors.toMap(s -> s, s -> 1, Integer::sum)); validateMapCount(count); } }
@Test public void testParallelStreamLargeBatch() throws FileNotFoundException { try( Stream<String> stream = ReaderSpliterator.lineStream(getReader(), 100)) { Map<String, Integer> count = stream.parallel().map(s -> s.trim()) .collect(Collectors.toMap(s -> s, s -> 1, Integer::sum)); validateMapCount(count); } }
@Test public void testSequentialStreamLargeBatch() throws FileNotFoundException { try( Stream<String> stream = ReaderSpliterator.lineStream(getReader(), 100)) { Map<String, Integer> count = stream.map(s -> s.trim()) .collect(Collectors.toMap(s -> s, s -> 1, Integer::sum)); validateMapCount(count); } }