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.
Merge pull request #3304 from non/bug/stream-flatten2-8100

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