SI-8100 - prevent possible SOE during Stream#flatten.

This commit changes stream flatten to avoid allocating a
stack frame for every stream item. Previously, flattening
a stream whose elements are mostly empty would result in
a StackOverflowException.

This commit also adds a test demonstrating the problem.