The following code breaks the stream of objects into pieces 1000, processes them during materialization, and returns the total number of objects at the end.
In all cases, the return number is true if the stream size is not 1. In the case where the stream size is 1, the return number is 0.
Any help would be greatly appreciated. I also had to crack the callback if there were no entries in the stream equal to 0. I would also like to fix this.
AtomicInteger recordCounter = new AtomicInteger(0); try (StreamEx<MyObject> stream = StreamEx.of(myObjects)) { stream.groupRuns((prev, next) -> recordCounter.incrementAndGet() % 1000 != 0) .forEach((chunk) -> { //... process each chunk } ); } catch(Exception e) { throw new MyRuntimeException("Failure streaming...", e); } finally { myObjects.close(); } return recordCounter.get() == 0 ? 0 : recordCounter.incrementAndGet();
source share